From 13c1c9d285cd395c1cf59d66642f836713bb726a Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Mon, 10 Nov 2025 23:30:13 +0530 Subject: [PATCH] SimpleChatTCRV:Vision: DataUrl helpers Move all dataUrl handling into helper functions. So that its manipulation is done in a controlled manner, as well as in future, changes to the semantic can be easily carried out by updating the helper functions suitably and inturn updating the caller as needed. For now avoid push and pop and work with 0th index directly, given that currently the logic is setup for handling only a single image with the ai model. This keeps things simple. It can be changed if required in future easily. --- tools/server/public_simplechat/simplechat.js | 31 ++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/tools/server/public_simplechat/simplechat.js b/tools/server/public_simplechat/simplechat.js index 66e45eea2d..278abaa176 100644 --- a/tools/server/public_simplechat/simplechat.js +++ b/tools/server/public_simplechat/simplechat.js @@ -972,9 +972,8 @@ class MultiChatUI { console.log(`DBUG:InFileX:${f0?.name}`) let fR = new FileReader() fR.onload = () => { - if ((fR.result) && (typeof(fR.result) == 'string')) { - this.me.dataURLs.push(fR.result) - this.elInFileX.elImg.src = fR.result + if (fR.result) { + this.dataurl_plus_add(fR.result) console.log(`INFO:InFileX:Loaded file ${f0.name}`) } } @@ -1034,9 +1033,31 @@ class MultiChatUI { } } + /** + * Add a dataUrl, as well as show Image. + * @param {string | ArrayBuffer | null} dataUrl + */ + dataurl_plus_add(dataUrl) { + if (typeof(dataUrl) == 'string') { + //this.me.dataURLs.push(dataUrl) + this.me.dataURLs[0] = dataUrl + this.elInFileX.elImg.src = dataUrl + } + } + + /** + * Get the stored dataUrl + */ + dataurl_get() { + //this.me.dataURLs.pop() + return /** @type{string} */(this.me.dataURLs[0]) + } + + /** + * Clear dataUrls, as well as clear Image. + */ dataurl_plus_clear() { this.elInFileX.elImg.src = ""; - //this.me.dataURLs.pop() this.me.dataURLs.length = 0; } @@ -1368,7 +1389,7 @@ class MultiChatUI { try { let image = undefined if (this.me.dataURLs.length > 0) { - image = /** @type{string} */(this.me.dataURLs[0]) + image = this.dataurl_get() } chat.add(new ChatMessageEx(new NSChatMessage(Roles.User, content, undefined, undefined, undefined, undefined, image))) } catch (err) {