From d44fb1ac0519db728ec1ba9c4834253bb03eaffa Mon Sep 17 00:00:00 2001 From: Kibi Kelburton Date: Fri, 22 May 2026 20:21:15 +0200 Subject: [PATCH] dynamic comment length --- public/s/js/upload.js | 5 ++++- src/inc/routes/apiv2/upload.mjs | 5 +++++ src/upload_handler.mjs | 7 ++++++- views/scroller.html | 2 +- views/snippets/upload-form.html | 4 ++-- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/public/s/js/upload.js b/public/s/js/upload.js index 0323cd1..de8d5bf 100644 --- a/public/s/js/upload.js +++ b/public/s/js/upload.js @@ -70,6 +70,8 @@ window.initUploadForm = (selector) => { // Dynamically get min tags requirement from DOM const minTags = parseInt(form.getAttribute('data-min-tags') || '3'); + const commentMaxLenAttr = form.getAttribute('data-comment-max-length'); + const commentMaxLen = (commentMaxLenAttr && commentMaxLenAttr !== 'null') ? parseInt(commentMaxLenAttr) : null; const isShitpost = form.classList.contains('shitpost-mode-active') || !!window.f0ckShitpostMode; let tags = []; @@ -870,9 +872,10 @@ window.initUploadForm = (selector) => { const commentPlaceholder = window.f0ckI18n?.upload_comment_placeholder || 'Comment (optional)...'; + const maxLenHtml = (commentMaxLen !== null && !isNaN(commentMaxLen)) ? ` maxlength="${commentMaxLen}"` : ''; commentUI = `
- +
diff --git a/src/inc/routes/apiv2/upload.mjs b/src/inc/routes/apiv2/upload.mjs index fa0c124..b8467b8 100644 --- a/src/inc/routes/apiv2/upload.mjs +++ b/src/inc/routes/apiv2/upload.mjs @@ -204,6 +204,11 @@ export default router => { const { url: inputUrl, rating, tags: tagsRaw, comment, is_oc, is_shitpost } = req.post || {}; + const maxLen = cfg.main.comment_max_length; + if (comment && maxLen !== null && maxLen !== undefined && comment.length > maxLen) { + return res.json({ success: false, msg: `Comment too long (max ${maxLen} characters)` }, 400); + } + if (!inputUrl || !inputUrl.trim()) { return res.json({ success: false, msg: 'URL is required' }, 400); } diff --git a/src/upload_handler.mjs b/src/upload_handler.mjs index d262659..86c128d 100644 --- a/src/upload_handler.mjs +++ b/src/upload_handler.mjs @@ -84,6 +84,11 @@ export const handleUpload = async (req, res, self) => { const is_shitpost = (parts.is_shitpost === 'true' || parts.is_shitpost === '1'); + const maxLen = cfg.main.comment_max_length; + if (comment && maxLen !== null && maxLen !== undefined && comment.length > maxLen) { + return sendJson(res, { success: false, msg: `Comment too long (max ${maxLen} characters)` }, 400); + } + if (!file || !file.data) { return sendJson(res, { success: false, msg: 'No file provided' }, 400); } @@ -380,7 +385,7 @@ export const handleUpload = async (req, res, self) => { } // Insert optional first comment - if (comment && comment.length > 0 && comment.length <= 2000) { + if (comment && comment.length > 0) { try { await db` INSERT INTO comments ${db({ diff --git a/views/scroller.html b/views/scroller.html index eaedd48..4dc7e6e 100644 --- a/views/scroller.html +++ b/views/scroller.html @@ -1286,7 +1286,7 @@
- +
diff --git a/views/snippets/upload-form.html b/views/snippets/upload-form.html index 270f7c6..d31b458 100644 --- a/views/snippets/upload-form.html +++ b/views/snippets/upload-form.html @@ -1,4 +1,4 @@ -
+
@if(web_url_upload)
@@ -109,7 +109,7 @@
- +