dynamic comment length

This commit is contained in:
2026-05-22 20:21:15 +02:00
parent b836ce37f3
commit d44fb1ac05
5 changed files with 18 additions and 5 deletions

View File

@@ -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 = `
<div class="item-comment-container">
<textarea class="item-comment-input" placeholder="${window.escapeHtmlUpload(commentPlaceholder)}">${window.escapeHtmlUpload(item.comment || '')}</textarea>
<textarea class="item-comment-input" placeholder="${window.escapeHtmlUpload(commentPlaceholder)}"${maxLenHtml}>${window.escapeHtmlUpload(item.comment || '')}</textarea>
<div class="item-comment-actions">
<button type="button" class="item-emoji-trigger" title="Emoji">&#x263A;</button>
</div>

View File

@@ -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);
}

View File

@@ -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({

View File

@@ -1286,7 +1286,7 @@
</div>
<div class="comment-input-row">
<button id="comment-emoji-trigger" class="emoji-trigger" title="Emoji" type="button"></button>
<textarea id="comment-input" rows="1" placeholder="{{ t('scroller.write_comment') }}" maxlength="2000"></textarea>
<textarea id="comment-input" rows="1" placeholder="{{ t('scroller.write_comment') }}"@if(comment_max_length) maxlength="{{ comment_max_length }}"@endif></textarea>
<button id="comment-send-btn" disabled><i class="fa-solid fa-paper-plane"></i></button>
</div>
</div>

View File

@@ -1,4 +1,4 @@
<form id="upload-form" class="upload-form {{ shitpost_mode ? 'shitpost-mode-active' : '' }}" enctype="multipart/form-data" data-mimes='{!! mimes_json !!}' data-max-bytes="{{ max_file_size_bytes }}" data-min-tags="{{ min_tags }}">
<form id="upload-form" class="upload-form {{ shitpost_mode ? 'shitpost-mode-active' : '' }}" enctype="multipart/form-data" data-mimes='{!! mimes_json !!}' data-max-bytes="{{ max_file_size_bytes }}" data-min-tags="{{ min_tags }}" data-comment-max-length="{{ comment_max_length }}">
<div class="form-section">
@if(web_url_upload)
<div class="upload-mode-tabs">
@@ -109,7 +109,7 @@
<div class="form-section global-comment-section">
<label>{{ t('upload.comment') }} <span style="opacity: 0.5; font-weight: normal;">{{ t('upload.comment_optional') }}</span></label>
<div class="upload-comment-input comment-input">
<textarea class="upload-comment" placeholder="{{ t('upload.comment_placeholder') }}" maxlength="2000"></textarea>
<textarea class="upload-comment" placeholder="{{ t('upload.comment_placeholder') }}"@if(comment_max_length) maxlength="{{ comment_max_length }}"@endif></textarea>
<div class="input-actions"></div>
</div>
</div>