From 91095e8d4ec5aad0edd378b9530bdbf18f40b142 Mon Sep 17 00:00:00 2001 From: perf3ct Date: Thu, 3 Oct 2024 22:23:51 -0700 Subject: [PATCH 1/3] detectFileTypeAndMime also returns the type, fixes #456 --- src/services/import/zip.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/services/import/zip.ts b/src/services/import/zip.ts index 8f9285443..22d32eedf 100644 --- a/src/services/import/zip.ts +++ b/src/services/import/zip.ts @@ -456,13 +456,12 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo return; } - let { mime } = noteMeta ? noteMeta : detectFileTypeAndMime(taskContext, filePath); + let { mime, type } = noteMeta ? noteMeta : detectFileTypeAndMime(taskContext, filePath); + type = resolveNoteType(type); if (mime == null) { throw new Error("Unable to resolve mime type."); } - let type = resolveNoteType(noteMeta?.type); - if (type !== 'file' && type !== 'image') { content = content.toString("utf-8"); } From c37a51c6d0db8373965a9ecce3aba2f3bccc6046 Mon Sep 17 00:00:00 2001 From: perf3ct Date: Thu, 3 Oct 2024 22:48:47 -0700 Subject: [PATCH 2/3] use type assertions to make TS happy? --- src/services/import/zip.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/import/zip.ts b/src/services/import/zip.ts index 22d32eedf..c2c06b1be 100644 --- a/src/services/import/zip.ts +++ b/src/services/import/zip.ts @@ -478,7 +478,7 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo // only skeleton was created because of altered order of cloned notes in ZIP, we need to update // https://github.com/zadam/trilium/issues/2440 if (note.type === undefined) { - note.type = type; + note.type = type as NoteType; note.mime = mime; note.title = noteTitle || ""; note.isProtected = isProtected; @@ -503,7 +503,7 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo title: noteTitle || "", content: content, noteId, - type, + type: type as NoteType, mime, prefix: noteMeta?.prefix || '', isExpanded: !!noteMeta?.isExpanded, From 5e80f120c94eec0b8532a16cf29289462917bd8e Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 10 Oct 2024 20:19:59 +0300 Subject: [PATCH 3/3] server: Refactor variable usage --- src/services/import/zip.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/services/import/zip.ts b/src/services/import/zip.ts index c2c06b1be..15d60482b 100644 --- a/src/services/import/zip.ts +++ b/src/services/import/zip.ts @@ -456,8 +456,8 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo return; } - let { mime, type } = noteMeta ? noteMeta : detectFileTypeAndMime(taskContext, filePath); - type = resolveNoteType(type); + let { mime, type: detectedType } = noteMeta ? noteMeta : detectFileTypeAndMime(taskContext, filePath); + const type = resolveNoteType(detectedType); if (mime == null) { throw new Error("Unable to resolve mime type."); } @@ -478,7 +478,7 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo // only skeleton was created because of altered order of cloned notes in ZIP, we need to update // https://github.com/zadam/trilium/issues/2440 if (note.type === undefined) { - note.type = type as NoteType; + note.type = type; note.mime = mime; note.title = noteTitle || ""; note.isProtected = isProtected; @@ -503,7 +503,7 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo title: noteTitle || "", content: content, noteId, - type: type as NoteType, + type, mime, prefix: noteMeta?.prefix || '', isExpanded: !!noteMeta?.isExpanded,