mirror of
https://github.com/zadam/trilium.git
synced 2026-03-09 21:50:24 +01:00
feat(import/single): trim extension for video files
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user