diff --git a/debug/clean.mjs b/debug/clean.mjs new file mode 100644 index 0000000..bbe08b2 --- /dev/null +++ b/debug/clean.mjs @@ -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); diff --git a/debug/test.mjs b/debug/test.mjs deleted file mode 100644 index 0b7e5ec..0000000 --- a/debug/test.mjs +++ /dev/null @@ -1,8 +0,0 @@ -import f0cklib from "../src/inc/routes/inc/f0cklib.mjs"; - -console.log( - await f0cklib.getRandom({ - user: '', - fav: true - }) -); diff --git a/package.json b/package.json index 16ca54b..f8c9fcb 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "start": "node --experimental-json-modules src/index.mjs", "trigger": "node --experimental-json-modules debug/trigger.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", "license": "MIT",