server-ts: Port share/routes

This commit is contained in:
Elian Doran
2024-04-10 19:04:38 +03:00
parent 88aba1c844
commit c08393f04b
9 changed files with 131 additions and 60 deletions

View File

@@ -8,10 +8,10 @@ import { Blob } from '../../../services/blob-interface';
class SAttachment extends AbstractShacaEntity {
private attachmentId: string;
private ownerId: string;
ownerId: string;
title: string;
role: string;
private mime: string;
mime: string;
private blobId: string;
/** used for caching of images */
private utcDateModified: string;

View File

@@ -7,7 +7,7 @@ class SBranch extends AbstractShacaEntity {
private branchId: string;
private noteId: string;
private parentNoteId: string;
parentNoteId: string;
private prefix: string;
private isExpanded: boolean;
isHidden: boolean;

View File

@@ -17,7 +17,7 @@ const isCredentials = (attr: SAttribute) => attr.type === 'label' && attr.name =
class SNote extends AbstractShacaEntity {
noteId: string;
private title: string;
title: string;
type: string;
mime: string;
private blobId: string;
@@ -223,6 +223,29 @@ class SNote extends AbstractShacaEntity {
}
}
/**
* @throws Error in case of invalid JSON
*/
getJsonContent(): any | null {
const content = this.getContent();
if (typeof content !== "string" || !content || !content.trim()) {
return null;
}
return JSON.parse(content);
}
/** @returns valid object or null if the content cannot be parsed as JSON */
getJsonContentSafely() {
try {
return this.getJsonContent();
}
catch (e) {
return null;
}
}
hasAttribute(type: string, name: string) {
return !!this.getAttributes().find(attr => attr.type === type && attr.name === name);
}

View File

@@ -10,10 +10,10 @@ export default class Shaca {
childParentToBranch!: Record<string, SBranch>;
private attributes!: Record<string, SAttribute>;
attachments!: Record<string, SAttachment>;
private aliasToNote!: Record<string, SNote>;
private shareRootNote!: SNote | null;
aliasToNote!: Record<string, SNote>;
shareRootNote!: SNote | null;
/** true if the index of all shared subtrees is enabled */
private shareIndexEnabled!: boolean;
shareIndexEnabled!: boolean;
loaded!: boolean;
constructor() {