From 635afe9f9f28b140971d0532e96ce8213602c1fd Mon Sep 17 00:00:00 2001 From: Kibi Kelburton Date: Wed, 27 May 2026 06:33:28 +0200 Subject: [PATCH] scroller filename as metadata --- public/s/js/scroller.js | 12 ++++++++++-- src/inc/routes/external.mjs | 7 ++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/public/s/js/scroller.js b/public/s/js/scroller.js index dcd4580..633e76a 100644 --- a/public/s/js/scroller.js +++ b/public/s/js/scroller.js @@ -209,6 +209,12 @@ if (!str) return ''; return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); } + function decodeHtmlEntities(str) { + if (!str) return ''; + const txt = document.createElement('textarea'); + txt.innerHTML = String(str); + return txt.value; + } function timeAgo(iso) { const s = Math.floor((Date.now() - new Date(iso)) / 1000); const i = window.f0ckI18n || {}; @@ -1690,7 +1696,8 @@ is_audio: false, comment_count: p.replies || 0, rating_label: isWsg ? 'SFW' : (isGif ? 'NSFW' : 'External'), - rating_class: isWsg ? 'sfw' : (isGif ? 'nsfw' : 'untagged') + rating_class: isWsg ? 'sfw' : (isGif ? 'nsfw' : 'untagged'), + original_filename: p.filename ? `${decodeHtmlEntities(p.filename)}${ext}` : null }; }) .filter(Boolean); @@ -1855,7 +1862,8 @@ url: item.external_media_url || item.dest, rating: rating, tags: '4chan', - comment: `Rehosted from 4chan thread: ${applied.externalUrl || 'unknown'}` + comment: `Rehosted from 4chan thread: ${applied.externalUrl || 'unknown'}`, + ...(item.original_filename ? { original_filename: item.original_filename } : {}) }) }); const data = await resp.json(); diff --git a/src/inc/routes/external.mjs b/src/inc/routes/external.mjs index 53e4f3c..8c98555 100644 --- a/src/inc/routes/external.mjs +++ b/src/inc/routes/external.mjs @@ -319,7 +319,7 @@ export default (router) => { // POST /api/v2/scroller/rehost // Downloads an external item and adds it to the platform router.post(/^\/api\/v2\/scroller\/rehost\/?$/, lib.loggedin, async (req, res) => { - const { url, rating: initialRating, tags: tagsRaw, comment, is_oc } = req.post || {}; + const { url, rating: initialRating, tags: tagsRaw, comment, is_oc, original_filename } = req.post || {}; if (!url) return res.reply({ code: 400, body: JSON.stringify({ success: false, msg: 'URL is required' }) }); @@ -436,8 +436,9 @@ export default (router) => { usernetwork: 'web', stamp: ~~(Date.now() / 1000), active: !isApprovalRequired, - is_oc: !!is_oc - }, 'src', 'dest', 'mime', 'size', 'checksum', 'phash', 'username', 'userchannel', 'usernetwork', 'stamp', 'active', 'is_oc')} + is_oc: !!is_oc, + original_filename: original_filename || null + }, 'src', 'dest', 'mime', 'size', 'checksum', 'phash', 'username', 'userchannel', 'usernetwork', 'stamp', 'active', 'is_oc', 'original_filename')} RETURNING id `;