clean dirs
This commit is contained in:
parent
6d185bd52f
commit
80cdf94a59
33
debug/clean.mjs
Normal file
33
debug/clean.mjs
Normal 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);
|
|
@ -1,8 +0,0 @@
|
||||||
import f0cklib from "../src/inc/routes/inc/f0cklib.mjs";
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
await f0cklib.getRandom({
|
|
||||||
user: '',
|
|
||||||
fav: true
|
|
||||||
})
|
|
||||||
);
|
|
|
@ -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",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user