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