diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.ts index 4428b6dde..4258c3805 100644 --- a/src/becca/entities/rows.ts +++ b/src/becca/entities/rows.ts @@ -91,7 +91,8 @@ export interface BranchRow { * end user. Those types should be used only for checking against, they are * not for direct use. */ -export type NoteType = ("file" | "image" | "search" | "noteMap" | "launcher" | "doc" | "contentWidget" | "text" | "relationMap" | "render" | "canvas" | "mermaid" | "book" | "webView" | "code"); +export const ALLOWED_NOTE_TYPES = [ "file", "image", "search", "noteMap", "launcher", "doc", "contentWidget", "text", "relationMap", "render", "canvas", "mermaid", "book", "webView", "code" ] as const; +export type NoteType = typeof ALLOWED_NOTE_TYPES[number]; export interface NoteRow { noteId: string; diff --git a/src/services/import/zip.ts b/src/services/import/zip.ts index 93ccc2da9..203b36442 100644 --- a/src/services/import/zip.ts +++ b/src/services/import/zip.ts @@ -20,7 +20,7 @@ import BNote = require('../../becca/entities/bnote'); import NoteMeta = require('../meta/note_meta'); import AttributeMeta = require('../meta/attribute_meta'); import { Stream } from 'stream'; -import { NoteType } from '../../becca/entities/rows'; +import { ALLOWED_NOTE_TYPES, NoteType } from '../../becca/entities/rows'; interface MetaFile { files: NoteMeta[] @@ -231,7 +231,7 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo if (!parentNoteId) { throw new Error("Missing parent note ID."); } - + const {note} = noteService.createNewNote({ parentNoteId: parentNoteId, title: noteTitle || "", @@ -462,13 +462,14 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo } let type = resolveNoteType(noteMeta?.type); + console.log("Resolved note type is ", noteMeta?.type, resolveNoteType(noteMeta?.type)); if (type !== 'file' && type !== 'image') { content = content.toString("utf-8"); } const noteTitle = utils.getNoteTitle(filePath, taskContext.data?.replaceUnderscoresWithSpaces || false, noteMeta); - + content = processNoteContent(noteMeta, type, mime, content, noteTitle || "", filePath); let note = becca.getNote(noteId); @@ -653,7 +654,11 @@ function resolveNoteType(type: string | undefined): NoteType { return 'webView'; } - return "text"; + if (type && (ALLOWED_NOTE_TYPES as readonly string[]).includes(type)) { + return type as NoteType; + } else { + return "text"; + } } export = {