From 7ebb730dd1d4caf79c8089b42b4d3e3bea9244f7 Mon Sep 17 00:00:00 2001 From: x Date: Sat, 24 Jan 2026 17:57:23 +0100 Subject: [PATCH] feat: add scripts for dummy item generation and thumbnail population, fix avatar foreign key constraint on item deletion, and improve admin approve view for empty trash. --- src/inc/routes/admin.mjs | 11 +++++++++++ views/admin/approve.html | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/inc/routes/admin.mjs b/src/inc/routes/admin.mjs index 9a86ce0..93d3068 100644 --- a/src/inc/routes/admin.mjs +++ b/src/inc/routes/admin.mjs @@ -249,6 +249,17 @@ export default (router, tpl) => { // Delete DB entries console.log('[ADMIN DENY] Deleting DB entries...'); try { + // Fix FK constraint: Check if this item is used as an avatar + try { + const fallback = await db`select id from items where active = true limit 1`; + if (fallback.length > 0) { + const safeId = fallback[0].id; + await db`update "user_options" set avatar = ${safeId} where avatar = ${id}`; + } + } catch (fkErr) { + console.error('[ADMIN DENY FK FIX ERROR]', fkErr); + } + await db`delete from "tags_assign" where item_id = ${id}`; await db`delete from "favorites" where item_id = ${id}`; await db`delete from "comments" where item_id = ${id}`.catch(() => { }); diff --git a/views/admin/approve.html b/views/admin/approve.html index 71b760a..2481c3c 100644 --- a/views/admin/approve.html +++ b/views/admin/approve.html @@ -44,10 +44,11 @@ @endif - @if(trash.length > 0)

Reference / Soft Deleted

These items are in the deleted folder but not purged from DB. Approving them will restore them.

+ + @if(trash.length > 0) @@ -85,6 +86,8 @@ @endeach
+ @else +

Trash is empty.

@endif @if(pending.length === 0 && trash.length === 0)