feat(import/single): trim extension for video files

This commit is contained in:
Elian Doran
2026-03-03 14:29:18 +02:00
parent 3ffe34964f
commit 4fd68bf12d
2 changed files with 7 additions and 3 deletions

View File

@@ -57,7 +57,7 @@ function importFile(taskContext: TaskContext<"importNotes">, file: File, parentN
const mime = mimeService.getMime(originalName) || file.mimetype;
const { note } = noteService.createNewNote({
parentNoteId: parentNote.noteId,
title: getNoteTitle(originalName, mime === "application/pdf"),
title: getNoteTitle(originalName, mime === "application/pdf", { mime }),
content: file.buffer,
isProtected: parentNote.isProtected && protectedSessionService.isProtectedSessionAvailable(),
type: "file",

View File

@@ -204,9 +204,13 @@ export function formatDownloadTitle(fileName: string, type: string | null, mime:
return `${fileNameBase}${getExtension()}`;
}
export function removeFileExtension(filePath: string) {
export function removeFileExtension(filePath: string, mime?: string) {
const extension = path.extname(filePath).toLowerCase();
if (mime?.startsWith("video/")) {
return filePath.substring(0, filePath.length - extension.length);
}
switch (extension) {
case ".md":
case ".mdx":
@@ -227,7 +231,7 @@ export function getNoteTitle(filePath: string, replaceUnderscoresWithSpaces: boo
const trimmedNoteMeta = noteMeta?.title?.trim();
if (trimmedNoteMeta) return trimmedNoteMeta;
const basename = path.basename(removeFileExtension(filePath));
const basename = path.basename(removeFileExtension(filePath, noteMeta?.mime));
return replaceUnderscoresWithSpaces ? basename.replace(/_/g, " ").trim() : basename;
}