From 1646fdba564a6bdb4eef2be7831d77d25c030e3b Mon Sep 17 00:00:00 2001 From: x Date: Sat, 24 Jan 2026 17:32:28 +0100 Subject: [PATCH] feat: Introduce `is_deleted` flag for items, add scripts for dummy data and thumbnail population, and refine item deletion and statistics. --- debug/fix_deleted.mjs | 20 ++++++++++++++++++-- src/inc/lib.mjs | 10 ++++++++-- src/inc/routes/apiv2/index.mjs | 2 +- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/debug/fix_deleted.mjs b/debug/fix_deleted.mjs index d1adcd2..58818e2 100644 --- a/debug/fix_deleted.mjs +++ b/debug/fix_deleted.mjs @@ -4,6 +4,22 @@ import { promises as fs } from "fs"; (async () => { console.log("Starting migration..."); + + // 1. Ensure column exists + try { + await db`select is_deleted from items limit 1`; + console.log("Column 'is_deleted' already exists."); + } catch (err) { + if (err.message.includes('column "is_deleted" does not exist')) { + console.log("Column 'is_deleted' missing. Adding it now..."); + await db`ALTER TABLE items ADD COLUMN is_deleted BOOLEAN DEFAULT FALSE`; + console.log("Column added successfully."); + } else { + console.error("Unexpected error checking column:", err); + process.exit(1); + } + } + const items = await db`select id, dest from items where active = false`; console.log(`Found ${items.length} inactive items.`); @@ -25,9 +41,9 @@ import { promises as fs } from "fs"; pendingCount++; } catch { // Not in either? Broken. - console.log(`Item ${item.id} (${item.dest}) missing from both locations.`); + console.log(`Item ${item.id} (${item.dest}) missing from both locations. Deleting...`); + await db`delete from items where id = ${item.id}`; brokenCount++; - // Default is false, which effectively puts it in pending queue as 'broken' } } } diff --git a/src/inc/lib.mjs b/src/inc/lib.mjs index 009c713..d072660 100644 --- a/src/inc/lib.mjs +++ b/src/inc/lib.mjs @@ -109,7 +109,12 @@ export default new class { const deleted = +(await db` select count(*) as total from "items" - where active = false + where active = false and is_deleted = true + `)[0].total; + const pending = +(await db` + select count(*) as total + from "items" + where active = false and is_deleted = false `)[0].total; const lastf0ck = +(await db` select max(id) as id @@ -120,7 +125,8 @@ export default new class { untagged, total: tagged + untagged, deleted, - untracked: lastf0ck - (tagged + untagged + deleted), + pending, + untracked: lastf0ck - (tagged + untagged + deleted + pending), sfw, nsfw, }; diff --git a/src/inc/routes/apiv2/index.mjs b/src/inc/routes/apiv2/index.mjs index 7ecedca..74dc282 100644 --- a/src/inc/routes/apiv2/index.mjs +++ b/src/inc/routes/apiv2/index.mjs @@ -267,7 +267,7 @@ export default router => { }); } - await db`update "items" set active = 'false' where id = ${id}`; + await db`update "items" set active = 'false', is_deleted = true where id = ${id}`; await fs.copyFile(`./public/b/${f0ck[0].dest}`, `./deleted/b/${f0ck[0].dest}`).catch(_ => { }); await fs.copyFile(`./public/t/${id}.webp`, `./deleted/t/${id}.webp`).catch(_ => { });