server: Fix note type import

A regression caused by the port to TypeScript caused all note types to
be treated as a "text" instead of other types such as canvas. The MIME
type, however, was unaffected.
This commit is contained in:
Elian Doran 2024-07-13 16:43:33 +03:00
parent e7c3dab56f
commit 1b0690ddfc
No known key found for this signature in database
2 changed files with 11 additions and 5 deletions

View File

@ -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;

View File

@ -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 = {