Skip to content

Build your personal knowledge base with Trilium Notes

fix(core): use of Node.js path

Elian Doran1d050e878486
diff --git a/packages/trilium-core/src/services/export/zip.ts b/packages/trilium-core/src/services/export/zip.ts
index 1d2287ebd5..6d8d49e4a3 100644
--- a/packages/trilium-core/src/services/export/zip.ts
+++ b/packages/trilium-core/src/services/export/zip.ts
@@ -1,5 +1,4 @@
import { NoteType } from "@triliumnext/commons";
-import path from "path";
import sanitize from "sanitize-filename";
import packageInfo from "../../../package.json" with { type: "json" };
@@ -17,6 +16,7 @@ import HtmlExportProvider from "./zip/html.js";
import MarkdownExportProvider from "./zip/markdown.js";
import { AttachmentMeta, AttributeMeta, ExportFormat, NoteMeta, NoteMetaFile } from "../../meta";
import { ValidationError } from "../../errors";
+import { extname } from "../utils/path";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async function exportToZip(taskContext: TaskContext<"export">, branch: BBranch, format: ExportFormat, res: Record<string, any>, setHeaders = true, zipExportOptions?: AdvancedExportOptions) {
@@ -91,7 +91,7 @@ async function exportToZip(taskContext: TaskContext<"export">, branch: BBranch,
fileName = fileName.slice(0, 30 - croppedExt.length) + croppedExt;
}
- const existingExtension = path.extname(fileName).toLowerCase();
+ const existingExtension = extname(fileName).toLowerCase();
const newExtension = provider.mapExtension(type, mime, existingExtension, format);
// if the note is already named with the extension (e.g. "image.jpg"), then it's silly to append the exact same extension again
diff --git a/packages/trilium-core/src/services/export/zip/html.ts b/packages/trilium-core/src/services/export/zip/html.ts
index 1c3d734177..a92a981ca7 100644
--- a/packages/trilium-core/src/services/export/zip/html.ts
+++ b/packages/trilium-core/src/services/export/zip/html.ts
@@ -1,8 +1,6 @@
-import fs from "fs";
import html from "html";
-import path from "path";
-import { escapeHtml, isDev } from "../../utils/index";
+import { escapeHtml } from "../../utils/index";
import { ZipExportProvider } from "./abstract_provider.js";
import { NoteMeta } from "../../../meta";
diff --git a/packages/trilium-core/src/services/import/single.spec.ts b/packages/trilium-core/src/services/import/single.spec.ts
index 4720bff43e..a749647fb6 100644
--- a/packages/trilium-core/src/services/import/single.spec.ts
+++ b/packages/trilium-core/src/services/import/single.spec.ts
@@ -1,6 +1,5 @@
import { beforeAll, describe, expect, it, vi } from "vitest";
import fs from "fs";
-import path from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
import becca from "../../becca/becca.js";
@@ -13,7 +12,7 @@ import { getContext } from "../context.js";
const scriptDir = dirname(fileURLToPath(import.meta.url));
async function testImport(fileName: string, mimetype: string) {
- const buffer = fs.readFileSync(path.join(scriptDir, "samples", fileName));
+ const buffer = fs.readFileSync(`${scriptDir}/samples/${fileName}`);
const taskContext = TaskContext.getInstance("import-mdx", "importNotes", {
textImportedAsText: true,
codeImportedAsCode: true
diff --git a/packages/trilium-core/src/services/import/zip.spec.ts b/packages/trilium-core/src/services/import/zip.spec.ts
index 397bce0db1..4921a529ff 100644
--- a/packages/trilium-core/src/services/import/zip.spec.ts
+++ b/packages/trilium-core/src/services/import/zip.spec.ts
@@ -1,6 +1,5 @@
import { beforeAll, describe, expect, it, vi } from "vitest";
import fs from "fs";
-import path from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
import zip, { removeTriliumTags } from "./zip.js";
@@ -13,7 +12,7 @@ import { getContext } from "../context.js";
const scriptDir = dirname(fileURLToPath(import.meta.url));
async function testImport(fileName: string) {
- const mdxSample = fs.readFileSync(path.join(scriptDir, "samples", fileName));
+ const mdxSample = fs.readFileSync(`${scriptDir}/samples/${fileName}`);
const taskContext = TaskContext.getInstance("import-mdx", "importNotes", {
textImportedAsText: true
});
diff --git a/packages/trilium-core/src/services/notes.ts b/packages/trilium-core/src/services/notes.ts
index 69f7601351..502ef1beb1 100644
--- a/packages/trilium-core/src/services/notes.ts
+++ b/packages/trilium-core/src/services/notes.ts
@@ -2,7 +2,6 @@ import { type AttachmentRow, type AttributeRow, type BranchRow, dayjs, type Note
import fs from "fs";
import html2plaintext from "html2plaintext";
import { t } from "i18next";
-import path from "path";
import url from "url";
import becca from "../becca/becca.js";
@@ -28,6 +27,7 @@ import { getSql } from "./sql/index.js";
import { sanitizeHtml } from "./sanitizer.js";
import { ValidationError } from "../errors.js";
import * as cls from "./context.js";
+import { basename } from "./utils/path.js";
interface FoundLink {
name: "imageLink" | "internalLink" | "includeNoteLink" | "relationMapLink";
@@ -552,7 +552,7 @@ async function downloadImage(noteId: string, imageUrl: string) {
}
const parsedUrl = url.parse(unescapedUrl);
- const title = path.basename(parsedUrl.pathname || "");
+ const title = basename(parsedUrl.pathname || "");
const attachment = imageService.saveImageToAttachment(noteId, imageBuffer, title, true, true);