diff --git a/public/s/js/f0ck.js b/public/s/js/f0ck.js index 16843f2..cbe08e7 100644 --- a/public/s/js/f0ck.js +++ b/public/s/js/f0ck.js @@ -988,7 +988,7 @@ class NotificationSystem { init() { this.bindEvents(); this.poll(); - setInterval(() => this.poll(), 60000); // Poll every minute + setInterval(() => this.poll(), 10000); // Poll every 10 seconds } bindEvents() { @@ -1065,6 +1065,30 @@ class NotificationSystem { } renderItem(n) { + if (n.type === 'approve') { + const link = `/${n.item_id}`; + return ` + + + Your Upload has been approved + + ${new Date(n.created_at).toLocaleString()} + + `; + } + + if (n.type === 'admin_pending') { + const link = '/admin/approve'; + return ` + + + A new upload needs approval + + ${new Date(n.created_at).toLocaleString()} + + `; + } + let typeText = 'Start'; if (n.type === 'comment_reply') typeText = 'replied to you'; else if (n.type === 'subscription') typeText = 'commented in a thread you follow'; diff --git a/src/inc/routes/admin.mjs b/src/inc/routes/admin.mjs index 829849d..f78e4e4 100644 --- a/src/inc/routes/admin.mjs +++ b/src/inc/routes/admin.mjs @@ -125,7 +125,7 @@ export default (router, tpl) => { if (req.url.qs?.id) { const id = +req.url.qs.id; const f0ck = await db` - select dest, mime + select dest, mime, username, id from "items" where id = ${id} and @@ -138,6 +138,19 @@ export default (router, tpl) => { }); } + // Notify User + try { + const uploader = await db`select id from "user" where login = ${f0ck[0].username} limit 1`; + if (uploader.length > 0) { + await db` + INSERT INTO notifications (user_id, type, reference_id, item_id) + VALUES (${uploader[0].id}, 'approve', 0, ${id}) + `; + } + } catch (err) { + console.error('[ADMIN APPROVE] Failed to notify user:', err); + } + await db`update "items" set active = 'true', is_deleted = false where id = ${id}`; // Check if files need moving (if they are in deleted/) diff --git a/src/inc/routes/notifications.mjs b/src/inc/routes/notifications.mjs index 34d4141..3175270 100644 --- a/src/inc/routes/notifications.mjs +++ b/src/inc/routes/notifications.mjs @@ -9,10 +9,11 @@ export default (router, tpl) => { try { const notifications = await db` SELECT n.id, n.type, n.item_id, n.reference_id, n.created_at, n.is_read, - u.user as from_user, u.id as from_user_id + COALESCE(u.user, 'System') as from_user, + COALESCE(u.id, 0) as from_user_id FROM notifications n - JOIN comments c ON n.reference_id = c.id - JOIN "user" u ON c.user_id = u.id + LEFT JOIN comments c ON n.reference_id = c.id + LEFT JOIN "user" u ON c.user_id = u.id WHERE n.user_id = ${req.session.id} AND n.is_read = false ORDER BY n.created_at DESC LIMIT 20 diff --git a/src/upload_handler.mjs b/src/upload_handler.mjs index ca3565b..15fa33d 100644 --- a/src/upload_handler.mjs +++ b/src/upload_handler.mjs @@ -241,6 +241,19 @@ export const handleUpload = async (req, res) => { `; } + // Notify Admins + try { + const admins = await db`select id from "user" where admin = true`; + for (const admin of admins) { + await db` + INSERT INTO notifications (user_id, type, reference_id, item_id) + VALUES (${admin.id}, 'admin_pending', 0, ${itemid}) + `; + } + } catch (err) { + console.error('[UPLOAD HANDLER] Failed to notify admins:', err); + } + return sendJson(res, { success: true, msg: 'Upload successful! Your upload is pending admin approval.',