mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
server-ts: Solve build errors after merge
This commit is contained in:
parent
db2b33704f
commit
08f0c01eef
@ -13,6 +13,7 @@ import BEtapiToken = require('./entities/betapi_token');
|
||||
import cls = require('../services/cls');
|
||||
import entityConstructor = require('../becca/entity_constructor');
|
||||
import { AttributeRow, BranchRow, EtapiTokenRow, NoteRow, OptionRow } from './entities/rows';
|
||||
import AbstractBeccaEntity = require('./entities/abstract_becca_entity');
|
||||
|
||||
const beccaLoaded = new Promise<void>((res, rej) => {
|
||||
sqlInit.dbReady.then(() => {
|
||||
@ -89,7 +90,7 @@ eventService.subscribeBeccaLoader([eventService.ENTITY_CHANGE_SYNCED], ({ entity
|
||||
if (beccaEntity) {
|
||||
beccaEntity.updateFromRow(entityRow);
|
||||
} else {
|
||||
beccaEntity = new EntityClass();
|
||||
beccaEntity = new EntityClass() as AbstractBeccaEntity<AbstractBeccaEntity<any>>;
|
||||
beccaEntity.updateFromRow(entityRow);
|
||||
beccaEntity.init();
|
||||
}
|
||||
|
@ -102,6 +102,10 @@ abstract class AbstractBeccaEntity<T extends AbstractBeccaEntity<T>> {
|
||||
|
||||
abstract getPojo(): {};
|
||||
|
||||
abstract init(): void;
|
||||
|
||||
abstract updateFromRow(row: unknown): void;
|
||||
|
||||
get isDeleted(): boolean {
|
||||
// TODO: Not sure why some entities don't implement it.
|
||||
return false;
|
||||
|
@ -37,10 +37,10 @@ class BAttachment extends AbstractBeccaEntity<BAttachment> {
|
||||
noteId?: number;
|
||||
attachmentId?: string;
|
||||
/** either noteId or revisionId to which this attachment belongs */
|
||||
ownerId: string;
|
||||
role: string;
|
||||
mime: string;
|
||||
title: string;
|
||||
ownerId!: string;
|
||||
role!: string;
|
||||
mime!: string;
|
||||
title!: string;
|
||||
type?: keyof typeof attachmentRoleToNoteTypeMapping;
|
||||
position?: number;
|
||||
blobId?: string;
|
||||
@ -54,6 +54,11 @@ class BAttachment extends AbstractBeccaEntity<BAttachment> {
|
||||
constructor(row: AttachmentRow) {
|
||||
super();
|
||||
|
||||
this.updateFromRow(row);
|
||||
this.decrypt();
|
||||
}
|
||||
|
||||
updateFromRow(row: AttachmentRow): void {
|
||||
if (!row.ownerId?.trim()) {
|
||||
throw new Error("'ownerId' must be given to initialize a Attachment entity");
|
||||
} else if (!row.role?.trim()) {
|
||||
@ -76,8 +81,10 @@ class BAttachment extends AbstractBeccaEntity<BAttachment> {
|
||||
this.utcDateModified = row.utcDateModified;
|
||||
this.utcDateScheduledForErasureSince = row.utcDateScheduledForErasureSince;
|
||||
this.contentLength = row.contentLength;
|
||||
}
|
||||
|
||||
this.decrypt();
|
||||
init(): void {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
copy(): BAttachment {
|
||||
|
@ -1657,6 +1657,10 @@ class BNote extends AbstractBeccaEntity<BNote> {
|
||||
position
|
||||
});
|
||||
|
||||
if (!content) {
|
||||
throw new Error("Attempted to save an attachment with no content.");
|
||||
}
|
||||
|
||||
attachment.setContent(content, {forceSave: true});
|
||||
|
||||
return attachment;
|
||||
|
@ -32,6 +32,10 @@ class BOption extends AbstractBeccaEntity<BOption> {
|
||||
this.utcDateModified = row.utcDateModified;
|
||||
}
|
||||
|
||||
init(): void {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
beforeSaving() {
|
||||
super.beforeSaving();
|
||||
|
||||
|
@ -12,18 +12,26 @@ class BRecentNote extends AbstractBeccaEntity<BRecentNote> {
|
||||
static get entityName() { return "recent_notes"; }
|
||||
static get primaryKeyName() { return "noteId"; }
|
||||
|
||||
noteId: string;
|
||||
notePath: string;
|
||||
utcDateCreated: string;
|
||||
noteId!: string;
|
||||
notePath!: string;
|
||||
utcDateCreated!: string;
|
||||
|
||||
constructor(row: RecentNoteRow) {
|
||||
super();
|
||||
|
||||
this.updateFromRow(row);
|
||||
}
|
||||
|
||||
updateFromRow(row: RecentNoteRow): void {
|
||||
this.noteId = row.noteId;
|
||||
this.notePath = row.notePath;
|
||||
this.utcDateCreated = row.utcDateCreated || dateUtils.utcNowDateTime();
|
||||
}
|
||||
|
||||
init(): void {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
getPojo() {
|
||||
return {
|
||||
noteId: this.noteId,
|
||||
|
@ -29,22 +29,30 @@ class BRevision extends AbstractBeccaEntity<BRevision> {
|
||||
"utcDateLastEdited", "utcDateCreated", "utcDateModified", "blobId"]; }
|
||||
|
||||
revisionId?: string;
|
||||
noteId: string;
|
||||
type: string;
|
||||
mime: string;
|
||||
isProtected: boolean;
|
||||
title: string;
|
||||
noteId!: string;
|
||||
type!: string;
|
||||
mime!: string;
|
||||
isProtected!: boolean;
|
||||
title!: string;
|
||||
blobId?: string;
|
||||
dateLastEdited?: string;
|
||||
dateCreated: string;
|
||||
dateCreated!: string;
|
||||
utcDateLastEdited?: string;
|
||||
utcDateCreated: string;
|
||||
utcDateCreated!: string;
|
||||
contentLength?: number;
|
||||
content?: string;
|
||||
|
||||
constructor(row: RevisionRow, titleDecrypted = false) {
|
||||
super();
|
||||
|
||||
this.updateFromRow(row);
|
||||
if (this.isProtected && !titleDecrypted) {
|
||||
const decryptedTitle = protectedSessionService.isProtectedSessionAvailable() ? protectedSessionService.decryptString(this.title) : null;
|
||||
this.title = decryptedTitle || "[protected]";
|
||||
}
|
||||
}
|
||||
|
||||
updateFromRow(row: RevisionRow) {
|
||||
this.revisionId = row.revisionId;
|
||||
this.noteId = row.noteId;
|
||||
this.type = row.type;
|
||||
@ -58,11 +66,10 @@ class BRevision extends AbstractBeccaEntity<BRevision> {
|
||||
this.utcDateCreated = row.utcDateCreated;
|
||||
this.utcDateModified = row.utcDateModified;
|
||||
this.contentLength = row.contentLength;
|
||||
}
|
||||
|
||||
if (this.isProtected && !titleDecrypted) {
|
||||
const decryptedTitle = protectedSessionService.isProtectedSessionAvailable() ? protectedSessionService.decryptString(this.title) : null;
|
||||
this.title = decryptedTitle || "[protected]";
|
||||
}
|
||||
init() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
getNote() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user