mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-28 10:32:27 +08:00
client-ts: Port services/entities/fblob
This commit is contained in:
parent
bece0aa784
commit
0c8092b8f4
@ -1,39 +0,0 @@
|
|||||||
export default class FBlob {
|
|
||||||
constructor(row) {
|
|
||||||
/** @type {string} */
|
|
||||||
this.blobId = row.blobId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* can either contain the whole content (in e.g. string notes), only part (large text notes) or nothing at all (binary notes, images)
|
|
||||||
* @type {string}
|
|
||||||
*/
|
|
||||||
this.content = row.content;
|
|
||||||
this.contentLength = row.contentLength;
|
|
||||||
|
|
||||||
/** @type {string} */
|
|
||||||
this.dateModified = row.dateModified;
|
|
||||||
/** @type {string} */
|
|
||||||
this.utcDateModified = row.utcDateModified;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns {*}
|
|
||||||
* @throws Error in case of invalid JSON */
|
|
||||||
getJsonContent() {
|
|
||||||
if (!this.content || !this.content.trim()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return JSON.parse(this.content);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @returns {*|null} valid object or null if the content cannot be parsed as JSON */
|
|
||||||
getJsonContentSafely() {
|
|
||||||
try {
|
|
||||||
return this.getJsonContent();
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
48
src/public/app/entities/fblob.ts
Normal file
48
src/public/app/entities/fblob.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
|
||||||
|
export interface FBlobRow {
|
||||||
|
blobId: string;
|
||||||
|
content: string;
|
||||||
|
contentLength: number;
|
||||||
|
dateModified: string;
|
||||||
|
utcDateModified: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class FBlob {
|
||||||
|
|
||||||
|
blobId: string;
|
||||||
|
/**
|
||||||
|
* can either contain the whole content (in e.g. string notes), only part (large text notes) or nothing at all (binary notes, images)
|
||||||
|
*/
|
||||||
|
content: string;
|
||||||
|
contentLength: number;
|
||||||
|
dateModified: string;
|
||||||
|
utcDateModified: string;
|
||||||
|
|
||||||
|
constructor(row: FBlobRow) {
|
||||||
|
this.blobId = row.blobId;
|
||||||
|
this.content = row.content;
|
||||||
|
this.contentLength = row.contentLength;
|
||||||
|
this.dateModified = row.dateModified;
|
||||||
|
this.utcDateModified = row.utcDateModified;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Error in case of invalid JSON
|
||||||
|
*/
|
||||||
|
getJsonContent(): unknown {
|
||||||
|
if (!this.content || !this.content.trim()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSON.parse(this.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
getJsonContentSafely(): unknown | null {
|
||||||
|
try {
|
||||||
|
return this.getJsonContent();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user