mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
better handling of not detected mime type
This commit is contained in:
parent
8561227622
commit
3f2229d9e1
@ -1,4 +1,4 @@
|
||||
FROM node:12.10.0-alpine
|
||||
FROM node:12.11.1-alpine
|
||||
|
||||
# Create app directory
|
||||
WORKDIR /usr/src/app
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PKG_DIR=dist/trilium-linux-x64-server
|
||||
NODE_VERSION=12.10.0
|
||||
NODE_VERSION=12.11.1
|
||||
|
||||
rm -r $PKG_DIR
|
||||
mkdir $PKG_DIR
|
||||
|
@ -64,6 +64,7 @@ const EXTENSION_TO_MIME = {
|
||||
".swift": "text/x-swift"
|
||||
};
|
||||
|
||||
/** @returns false if MIME is not detected */
|
||||
function getMime(fileName) {
|
||||
if (fileName.toLowerCase() === 'dockerfile') {
|
||||
return "text/x-dockerfile";
|
||||
|
@ -8,7 +8,7 @@ const path = require('path');
|
||||
const mimeService = require('./mime');
|
||||
|
||||
async function importSingleFile(importContext, file, parentNote) {
|
||||
const mime = mimeService.getMime(file.originalname);
|
||||
const mime = mimeService.getMime(file.originalname) || file.mimetype;
|
||||
|
||||
if (importContext.textImportedAsText) {
|
||||
if (mime === 'text/html') {
|
||||
@ -42,13 +42,12 @@ async function importImage(file, parentNote, importContext) {
|
||||
async function importFile(importContext, file, parentNote) {
|
||||
const originalName = file.originalname;
|
||||
const size = file.size;
|
||||
const mime = mimeService.getMime(originalName);
|
||||
|
||||
const {note} = await noteService.createNote(parentNote.noteId, originalName, file.buffer, {
|
||||
target: 'into',
|
||||
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),
|
||||
type: 'file',
|
||||
mime: mime === false ? file.mimetype : mime,
|
||||
mime: mimeService.getMime(originalName) || file.mimetype,
|
||||
attributes: [
|
||||
{ type: "label", name: "originalFileName", value: originalName },
|
||||
{ type: "label", name: "fileSize", value: size }
|
||||
@ -63,7 +62,7 @@ async function importFile(importContext, file, parentNote) {
|
||||
async function importCodeNote(importContext, file, parentNote) {
|
||||
const title = getFileNameWithoutExtension(file.originalname);
|
||||
const content = file.buffer.toString("UTF-8");
|
||||
const detectedMime = mimeService.getMime(file.originalname);
|
||||
const detectedMime = mimeService.getMime(file.originalname) || file.mimetype;
|
||||
const mime = mimeService.normalizeMimeType(detectedMime);
|
||||
|
||||
const {note} = await noteService.createNote(parentNote.noteId, title, content, {
|
||||
|
@ -132,7 +132,7 @@ async function importTar(importContext, fileBuffer, importRootNote) {
|
||||
}
|
||||
|
||||
function detectFileTypeAndMime(importContext, filePath) {
|
||||
const mime = mimeService.getMime(filePath);
|
||||
const mime = mimeService.getMime(filePath) || "application/octet-stream";
|
||||
const type = mimeService.getType(importContext, mime);
|
||||
|
||||
return { mime, type };
|
||||
|
@ -86,9 +86,12 @@ async function findNotes(query) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// trim is necessary because even with .split() trailing spaces are tokens which causes havoc
|
||||
// filtering '/' because it's used as separator
|
||||
const allTokens = query.trim().toLowerCase().split(" ").filter(token => token !== '/');
|
||||
const allTokens = query
|
||||
.trim() // necessary because even with .split() trailing spaces are tokens which causes havoc
|
||||
.toLowerCase()
|
||||
.split(/[ -]/)
|
||||
.filter(token => token !== '/'); // '/' is used as separator
|
||||
|
||||
const tokens = allTokens.slice();
|
||||
let results = [];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user