tool: autotagger
This commit is contained in:
parent
9a3b494a94
commit
30cdd09e58
33
debug/autotagger.mjs
Normal file
33
debug/autotagger.mjs
Normal 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);
|
||||
}
|
||||
};
|
||||
})();
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue
Block a user