feat: Implement is_deleted flag for items, add new utility scripts, and refine UI styles.

This commit is contained in:
x
2026-01-24 17:24:22 +01:00
parent ee416a1d08
commit 63e86e9be1
9 changed files with 265 additions and 145 deletions

View File

@@ -138,7 +138,7 @@ export default (router, tpl) => {
});
}
await db`update "items" set active = 'true' where id = ${id}`;
await db`update "items" set active = 'true', is_deleted = false where id = ${id}`;
// Check if files need moving (if they are in deleted/)
try {
@@ -169,51 +169,56 @@ export default (router, tpl) => {
const total = (await db`select count(*) as c from "items" where active = 'false'`)[0].c;
const pages = Math.ceil(total / limit);
const _posts = await db`
select id, mime, username, dest
from "items"
// Fetch Pending (not deleted)
const pending = await db`
select i.id, i.mime, i.username, i.dest, array_agg(t.tag) as tags
from "items" i
left join "tags_assign" ta on ta.item_id = i.id
left join "tags" t on t.id = ta.tag_id
where
active = 'false'
order by id desc
limit ${limit} offset ${offset}
i.active = 'false' and i.is_deleted = false
group by i.id
order by i.id desc
`;
if (_posts.length === 0 && page > 1) {
// if page empty, maybe redirect to last page or page 1?
// Just render empty for now
}
// Fetch Trash (deleted)
const trash = await db`
select i.id, i.mime, i.username, i.dest, array_agg(t.tag) as tags
from "items" i
left join "tags_assign" ta on ta.item_id = i.id
left join "tags" t on t.id = ta.tag_id
where
i.active = 'false' and i.is_deleted = true
group by i.id
order by i.id desc
`;
if (_posts.length === 0) {
return res.reply({
body: tpl.render('admin/approve', { posts: [], pages: 0, page: 1, tmp: null }, req)
});
}
const posts = await Promise.all(_posts.map(async p => {
// Try to get thumbnail from public or deleted
let thumb;
try {
// Try public first
thumb = (await fs.readFile(`./public/t/${p.id}.webp`)).toString('base64');
} catch {
// Helper to process thumbnails
const processItems = async (items, isInTrash) => {
return Promise.all(items.map(async p => {
let thumb = '';
const path = isInTrash ? 'deleted' : 'public';
try {
thumb = (await fs.readFile(`./deleted/t/${p.id}.webp`)).toString('base64');
} catch {
thumb = ""; // No thumbnail?
}
}
return {
...p,
thumbnail: thumb
};
}));
thumb = (await fs.readFile(`./${path}/t/${p.id}.webp`)).toString('base64');
} catch { }
return {
...p,
thumbnail: thumb,
tags: p.tags.filter(t => t !== null)
};
}));
};
const pendingProcessed = await processItems(pending, false);
const trashProcessed = await processItems(trash, true);
res.reply({
body: tpl.render('admin/approve', {
posts,
pending: pendingProcessed,
trash: trashProcessed,
page,
pages,
stats: { total: posts.length },
stats: { total: pending.length + trash.length },
tmp: null
}, req)
});