mirror of
https://github.com/zadam/trilium.git
synced 2026-05-07 06:57:16 +02:00
fix(core): use of Node.js path
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user