From 0c8092b8f4b37f82d546dc75250b3376c1b5a997 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 25 Jul 2024 00:13:53 +0300 Subject: [PATCH] client-ts: Port services/entities/fblob --- src/public/app/entities/fblob.js | 39 -------------------------- src/public/app/entities/fblob.ts | 48 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 39 deletions(-) delete mode 100644 src/public/app/entities/fblob.js create mode 100644 src/public/app/entities/fblob.ts diff --git a/src/public/app/entities/fblob.js b/src/public/app/entities/fblob.js deleted file mode 100644 index e335d7cb8..000000000 --- a/src/public/app/entities/fblob.js +++ /dev/null @@ -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; - } - } -} diff --git a/src/public/app/entities/fblob.ts b/src/public/app/entities/fblob.ts new file mode 100644 index 000000000..d260f7da6 --- /dev/null +++ b/src/public/app/entities/fblob.ts @@ -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; + } + } +}