mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
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:
parent
e7c3dab56f
commit
1b0690ddfc
@ -91,7 +91,8 @@ export interface BranchRow {
|
|||||||
* end user. Those types should be used only for checking against, they are
|
* end user. Those types should be used only for checking against, they are
|
||||||
* not for direct use.
|
* 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 {
|
export interface NoteRow {
|
||||||
noteId: string;
|
noteId: string;
|
||||||
|
@ -20,7 +20,7 @@ import BNote = require('../../becca/entities/bnote');
|
|||||||
import NoteMeta = require('../meta/note_meta');
|
import NoteMeta = require('../meta/note_meta');
|
||||||
import AttributeMeta = require('../meta/attribute_meta');
|
import AttributeMeta = require('../meta/attribute_meta');
|
||||||
import { Stream } from 'stream';
|
import { Stream } from 'stream';
|
||||||
import { NoteType } from '../../becca/entities/rows';
|
import { ALLOWED_NOTE_TYPES, NoteType } from '../../becca/entities/rows';
|
||||||
|
|
||||||
interface MetaFile {
|
interface MetaFile {
|
||||||
files: NoteMeta[]
|
files: NoteMeta[]
|
||||||
@ -231,7 +231,7 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo
|
|||||||
if (!parentNoteId) {
|
if (!parentNoteId) {
|
||||||
throw new Error("Missing parent note ID.");
|
throw new Error("Missing parent note ID.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const {note} = noteService.createNewNote({
|
const {note} = noteService.createNewNote({
|
||||||
parentNoteId: parentNoteId,
|
parentNoteId: parentNoteId,
|
||||||
title: noteTitle || "",
|
title: noteTitle || "",
|
||||||
@ -462,13 +462,14 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo
|
|||||||
}
|
}
|
||||||
|
|
||||||
let type = resolveNoteType(noteMeta?.type);
|
let type = resolveNoteType(noteMeta?.type);
|
||||||
|
console.log("Resolved note type is ", noteMeta?.type, resolveNoteType(noteMeta?.type));
|
||||||
|
|
||||||
if (type !== 'file' && type !== 'image') {
|
if (type !== 'file' && type !== 'image') {
|
||||||
content = content.toString("utf-8");
|
content = content.toString("utf-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
const noteTitle = utils.getNoteTitle(filePath, taskContext.data?.replaceUnderscoresWithSpaces || false, noteMeta);
|
const noteTitle = utils.getNoteTitle(filePath, taskContext.data?.replaceUnderscoresWithSpaces || false, noteMeta);
|
||||||
|
|
||||||
content = processNoteContent(noteMeta, type, mime, content, noteTitle || "", filePath);
|
content = processNoteContent(noteMeta, type, mime, content, noteTitle || "", filePath);
|
||||||
|
|
||||||
let note = becca.getNote(noteId);
|
let note = becca.getNote(noteId);
|
||||||
@ -653,7 +654,11 @@ function resolveNoteType(type: string | undefined): NoteType {
|
|||||||
return 'webView';
|
return 'webView';
|
||||||
}
|
}
|
||||||
|
|
||||||
return "text";
|
if (type && (ALLOWED_NOTE_TYPES as readonly string[]).includes(type)) {
|
||||||
|
return type as NoteType;
|
||||||
|
} else {
|
||||||
|
return "text";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export = {
|
export = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user