mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
Merge pull request #198 from TriliumNext/bugfix/note_import_type
Fix import note type
This commit is contained in:
commit
6ecbf1c528
@ -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;
|
||||||
@ -106,5 +107,5 @@ export interface NoteRow {
|
|||||||
dateModified: string;
|
dateModified: string;
|
||||||
utcDateCreated: string;
|
utcDateCreated: string;
|
||||||
utcDateModified: string;
|
utcDateModified: string;
|
||||||
content?: string;
|
content?: string | Buffer;
|
||||||
}
|
}
|
||||||
|
@ -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[]
|
||||||
@ -499,10 +499,6 @@ async function importZip(taskContext: TaskContext, fileBuffer: Buffer, importRoo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (typeof content !== "string") {
|
|
||||||
throw new Error("Incorrect content type.");
|
|
||||||
}
|
|
||||||
|
|
||||||
({note} = noteService.createNewNote({
|
({note} = noteService.createNewNote({
|
||||||
parentNoteId: parentNoteId,
|
parentNoteId: parentNoteId,
|
||||||
title: noteTitle || "",
|
title: noteTitle || "",
|
||||||
@ -653,7 +649,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 = {
|
||||||
|
@ -7,7 +7,7 @@ export interface NoteParams {
|
|||||||
parentNoteId: string;
|
parentNoteId: string;
|
||||||
templateNoteId?: string;
|
templateNoteId?: string;
|
||||||
title: string;
|
title: string;
|
||||||
content: string;
|
content: string | Buffer;
|
||||||
/** text, code, file, image, search, book, relationMap, canvas, webView */
|
/** text, code, file, image, search, book, relationMap, canvas, webView */
|
||||||
type: NoteType;
|
type: NoteType;
|
||||||
/** default value is derived from default mimes for type */
|
/** default value is derived from default mimes for type */
|
||||||
|
@ -74,7 +74,7 @@ class NoteContentFulltextExp extends Expression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isProtected) {
|
if (isProtected) {
|
||||||
if (!protectedSessionService.isProtectedSessionAvailable() || !content) {
|
if (!protectedSessionService.isProtectedSessionAvailable() || !content || typeof content !== "string") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ class NoteContentFulltextExp extends Expression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!content) {
|
if (!content || typeof content !== "string") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user