Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(core): extension lookup failing in standalone
Elian Dorana0573c439b69
diff --git a/packages/trilium-core/src/routes/api/import.ts b/packages/trilium-core/src/routes/api/import.tsindex 4d68e504f4..b3bcdff357 100644--- a/packages/trilium-core/src/routes/api/import.ts+++ b/packages/trilium-core/src/routes/api/import.ts@@ -1,5 +1,4 @@import type { Request } from "express";-import path from "path";import type { File } from "../../services/import/common.js";interface ImportRequest<P> extends Request<P> {@@ -12,12 +11,13 @@ import enexImportService from "../../services/import/enex.js";import opmlImportService from "../../services/import/opml.js";import singleImportService from "../../services/import/single.js";import zipImportService from "../../services/import/zip.js";-import log, { getLog } from "../../services/log.js";+import { getLog } from "../../services/log.js";import TaskContext from "../../services/task_context.js";import { safeExtractMessageAndStackFromError } from "../../services/utils/index.js";import * as cls from "../../services/context.js";import { ValidationError } from "../../errors.js";import becca_loader from "../../becca/becca_loader.js";+import { extname } from "../../services/utils/path.js";async function importNotesToBranch(req: ImportRequest<{ parentNoteId: string }>) {const { parentNoteId } = req.params;@@ -40,7 +40,7 @@ async function importNotesToBranch(req: ImportRequest<{ parentNoteId: string }>)const parentNote = becca.getNoteOrThrow(parentNoteId);- const extension = path.extname(file.originalname).toLowerCase();+ const extension = extname(file.originalname).toLowerCase();// running all the event handlers on imported notes (and attributes) is slow// and may produce unintended consequencesdiff --git a/packages/trilium-core/src/routes/api/revisions.ts b/packages/trilium-core/src/routes/api/revisions.tsindex 5620cb1400..22b62ffcba 100644--- a/packages/trilium-core/src/routes/api/revisions.ts+++ b/packages/trilium-core/src/routes/api/revisions.ts@@ -1,6 +1,5 @@import { EditedNotesResponse, RevisionItem, RevisionPojo } from "@triliumnext/commons";import type { Request, Response } from "express";-import path from "path";import becca from "../../becca/becca.js";import type BNote from "../../becca/entities/bnote.js";@@ -10,6 +9,7 @@ import eraseService from "../../services/erase.js";import { NotePojo } from "../../becca/becca-interface.js";import { becca_service, binary_utils, cls, getSql } from "../../index.js";import { formatDownloadTitle, getContentDisposition } from "../../services/utils/index.js";+import { extname } from "../../services/utils/path.js";interface NotePath {noteId: string;@@ -67,7 +67,7 @@ function getRevisionFilename(revision: BRevision) {throw new Error("Missing creation date for revision.");}- const extension = path.extname(filename);+ const extension = extname(filename);const date = revision.dateCreated.substr(0, 19).replace(" ", "_")diff --git a/packages/trilium-core/src/services/import/mime.ts b/packages/trilium-core/src/services/import/mime.tsindex b25e98926d..9ce41324ce 100644--- a/packages/trilium-core/src/services/import/mime.ts+++ b/packages/trilium-core/src/services/import/mime.ts@@ -1,8 +1,8 @@"use strict";-import mimeTypes from "mime-types";-import path from "path";+import { types as extToMime } from "mime-types";import type { NoteType, TaskData } from "@triliumnext/commons";+import { extname } from "../utils/path";const CODE_MIME_TYPES = new Set(["application/json",@@ -84,10 +84,10 @@ function getMime(fileName: string) {return "text/x-dockerfile";}- const ext = path.extname(fileNameLc);+ const ext = extname(fileNameLc);const mimeFromExt = EXTENSION_TO_MIME.get(ext);- return mimeFromExt || mimeTypes.lookup(fileNameLc);+ return mimeFromExt || extToMime[ext.slice(1)] || false;}function getType(options: TaskData<"importNotes">, mime: string): NoteType {