clean dirs

This commit is contained in:
Flummi 2022-01-02 15:15:54 +01:00
parent 6d185bd52f
commit 80cdf94a59
3 changed files with 34 additions and 9 deletions

33
debug/clean.mjs Normal file
View File

@ -0,0 +1,33 @@
import sql from "../src/inc/sql.mjs";
import { promises as fs } from "fs";
const opts = {
b: "public/b",
t: "public/t",
tmp: "tmp"
};
const count = {
b: 0, t: 0, tmp: 0
};
const rows = await sql('items').select('id', 'dest');
const ids = rows.map(r => r.id.toString() + ".png");
const dests = rows.map(r => r.dest);
const files = {
b: (await fs.readdir(opts.b)).filter(f => f !== '.empty'),
t: await fs.readdir(opts.t)
};
const unused = {
b: files.b.filter(f => !dests.includes(f)),
t: files.t.filter(f => !ids.includes(f))
}
count.b = (await Promise.all(unused.b.map(f => fs.rm(`${opts.b}/${f}`)))).length;
count.t = (await Promise.all(unused.t.map(f => fs.rm(`${opts.t}/${f}`)))).length;
// clear tmp
const tmp = (await fs.readdir(opts.tmp)).filter(f => f !== '.empty');
count.tmp = (await Promise.all(tmp.map(f => fs.rm(`${opts.tmp}/${f}`)))).length;
console.log(count);

View File

@ -1,8 +0,0 @@
import f0cklib from "../src/inc/routes/inc/f0cklib.mjs";
console.log(
await f0cklib.getRandom({
user: '',
fav: true
})
);

View File

@ -7,7 +7,7 @@
"start": "node --experimental-json-modules src/index.mjs", "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", "autotagger": "node --experimental-json-modules debug/autotagger.mjs",
"test": "node --experimental-json-modules debug/test.mjs" "clean": "node --experimental-json-modules debug/clean.mjs"
}, },
"author": "Flummi", "author": "Flummi",
"license": "MIT", "license": "MIT",