tool: autotagger

This commit is contained in:
Flummi 2021-12-26 17:24:42 +01:00
parent 9a3b494a94
commit 30cdd09e58
2 changed files with 35 additions and 1 deletions

33
debug/autotagger.mjs Normal file
View File

@ -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);
}
};
})();

View File

@ -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",