feat(import/single): remove extension from title for PDF imports

This commit is contained in:
Elian Doran 2026-01-16 12:01:11 +02:00
parent df62dc87b2
commit 3a0880fcd6
No known key found for this signature in database

View File

@ -1,18 +1,17 @@
"use strict";
import type { NoteType } from "@triliumnext/commons";
import { extname } from "path";
import type BNote from "../../becca/entities/bnote.js";
import type TaskContext from "../task_context.js";
import noteService from "../../services/notes.js";
import imageService from "../../services/image.js";
import noteService from "../../services/notes.js";
import { getNoteTitle, processStringOrBuffer } from "../../services/utils.js";
import htmlSanitizer from "../html_sanitizer.js";
import protectedSessionService from "../protected_session.js";
import type TaskContext from "../task_context.js";
import type { File } from "./common.js";
import markdownService from "./markdown.js";
import mimeService from "./mime.js";
import { getNoteTitle, processStringOrBuffer } from "../../services/utils.js";
import importUtils from "./utils.js";
import htmlSanitizer from "../html_sanitizer.js";
import type { File } from "./common.js";
import type { NoteType } from "@triliumnext/commons";
function importSingleFile(taskContext: TaskContext<"importNotes">, file: File, parentNote: BNote) {
const mime = mimeService.getMime(file.originalname) || file.mimetype;
@ -58,7 +57,7 @@ function importFile(taskContext: TaskContext<"importNotes">, file: File, parentN
const { note } = noteService.createNewNote({
parentNoteId: parentNote.noteId,
title: originalName,
title: removeFileExtension(originalName),
content: file.buffer,
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),
type: "file",
@ -72,6 +71,17 @@ function importFile(taskContext: TaskContext<"importNotes">, file: File, parentN
return note;
}
function removeFileExtension(filename: string) {
const extension = extname(filename).toLowerCase();
switch (extension) {
case ".pdf":
return filename.substring(0, filename.length - extension.length);
default:
return filename;
}
}
function importCodeNote(taskContext: TaskContext<"importNotes">, file: File, parentNote: BNote) {
const title = getNoteTitle(file.originalname, !!taskContext.data?.replaceUnderscoresWithSpaces);
const content = processStringOrBuffer(file.buffer);
@ -88,7 +98,7 @@ function importCodeNote(taskContext: TaskContext<"importNotes">, file: File, par
title,
content,
type,
mime: mime,
mime,
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable()
});
@ -106,7 +116,7 @@ function importCustomType(taskContext: TaskContext<"importNotes">, file: File, p
title,
content,
type,
mime: mime,
mime,
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable()
});
@ -214,7 +224,7 @@ function importAttachment(taskContext: TaskContext<"importNotes">, file: File, p
title: file.originalname,
content: file.buffer,
role: "file",
mime: mime
mime
});
taskContext.increaseProgressCount();