From 30cdd09e58b26f705a56a4eb0030c2bb24bf90b5 Mon Sep 17 00:00:00 2001 From: Flummi Date: Sun, 26 Dec 2021 17:24:42 +0100 Subject: [PATCH] tool: autotagger --- debug/autotagger.mjs | 33 +++++++++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 debug/autotagger.mjs diff --git a/debug/autotagger.mjs b/debug/autotagger.mjs new file mode 100644 index 0000000..0b6d293 --- /dev/null +++ b/debug/autotagger.mjs @@ -0,0 +1,33 @@ +import sql from "../src/inc/sql.mjs"; +import cfg from "../src/inc/config.mjs"; +import fetch from "flumm-fetch-cookies"; + +(async () => { + const _args = process.argv.slice(2); + const _from = +_args[0]; + const _to = _from + 100; + + const f0cks = await sql("items") + .whereRaw("id not in (select item_id from tags_assign group by item_id)") + .andWhere("mime", "like", "image/%") + .andWhereBetween("id", [ _from, _to ]); + + const body = { headers: { Authorization: `Basic ${cfg.tagger.btoa}` } }; + + for(let f of f0cks) { + let tag; + const res = await (await fetch(`${cfg.tagger.endpoint}/categories/nsfw_beta?image_url=${cfg.main.url}/b/${f.dest}`, body)).json(); + if(res?.result) { + tag = (res.result.categories[0].name.en === "safe") ? "sfw" : "nsfw"; + + await sql("tags_assign").insert({ + tag_id: tag === "sfw" ? 1 : 2, + item_id: f.id, + user_id: 7 // user: autotagger + }); + } + else { + console.log(res); + } + }; +})(); diff --git a/package.json b/package.json index 7df61e9..14d8c2a 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.mjs", "scripts": { "start": "node --experimental-json-modules src/index.mjs", - "trigger": "node --experimental-json-modules debug/trigger.mjs" + "trigger": "node --experimental-json-modules debug/trigger.mjs", + "autotagger": "node --experimental-json-modules debug/autotagger.mjs" }, "author": "Flummi", "license": "MIT",