From 39f59d129d10cc2015388406eef68b21bb625adb Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Thu, 2 May 2024 09:50:47 +0800 Subject: [PATCH] Immediately set the current URL even prior to analysis. --- scripts/external/processor.js | 10 ++++++++-- scripts/product.js | 8 +++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/external/processor.js b/scripts/external/processor.js index b42e06e..11f5925 100644 --- a/scripts/external/processor.js +++ b/scripts/external/processor.js @@ -5,6 +5,7 @@ Process the information on the website and display it on screen. import scraper from "/scripts/external/scraper.js"; import product from "/scripts/product.js"; import injection from "/scripts/GUI/entrypoints/inject.js" +import {global} from "/scripts/secretariat.js"; export default class processor { #filter; @@ -23,13 +24,18 @@ export default class processor { constructor (filter) { this.#filter = filter; + this.notify(); + this.targets = this.#filter[`data`]; this.scrape(); if ((this.data) ? (((typeof (this.data)).includes(`obj`) && !Array.isArray(this.data)) ? Object.keys(this.data) : this.data) : false) { this.analyze(); - } - + } + + async notify () { + // Indicate that this is the last updated. + await global.write([`last`], this.URL, -1); } } \ No newline at end of file diff --git a/scripts/product.js b/scripts/product.js index 261e46f..93c7c19 100644 --- a/scripts/product.js +++ b/scripts/product.js @@ -43,9 +43,6 @@ export default class product { // Add the data digest. this.#snip = (await hash.digest(this.details, {"output": "Array"})); - // Indicate that this is the last updated. - await session.write([`last`], this.URL); - // Add the status about this data. this.status = {}; this.status[`update`] = !(await (compare([`sites`, this.URL, `snip`], this.#snip))); @@ -70,6 +67,8 @@ export default class product { }; async analyze() { + console.log(`run`, this[`analysis`], this.status ? (!this.status.update) : false); + // Stop when the data is already analyzed. if (this[`analysis`]) {return(this.analysis)} else if (this.status ? (!this.status.update) : false) {this.analysis = await global.read([`sites`, this.URL, `analysis`]);} @@ -85,9 +84,12 @@ export default class product { PROMPT.push({"text": ((new texts(`AI_message_prompt`)).localized).concat(JSON.stringify(this.details))}); try { + // Run the analysis. await analyzer.generate(PROMPT); + console.log(`done`, analyzer.blocked); + // Raise an error if the product analysis is blocked. if (analyzer.blocked) { throw new Error((new texts(`error_msg_blocked`)).localized)