dynamic comment length
This commit is contained in:
@@ -70,6 +70,8 @@ window.initUploadForm = (selector) => {
|
|||||||
|
|
||||||
// Dynamically get min tags requirement from DOM
|
// Dynamically get min tags requirement from DOM
|
||||||
const minTags = parseInt(form.getAttribute('data-min-tags') || '3');
|
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;
|
const isShitpost = form.classList.contains('shitpost-mode-active') || !!window.f0ckShitpostMode;
|
||||||
let tags = [];
|
let tags = [];
|
||||||
@@ -870,9 +872,10 @@ window.initUploadForm = (selector) => {
|
|||||||
|
|
||||||
|
|
||||||
const commentPlaceholder = window.f0ckI18n?.upload_comment_placeholder || 'Comment (optional)...';
|
const commentPlaceholder = window.f0ckI18n?.upload_comment_placeholder || 'Comment (optional)...';
|
||||||
|
const maxLenHtml = (commentMaxLen !== null && !isNaN(commentMaxLen)) ? ` maxlength="${commentMaxLen}"` : '';
|
||||||
commentUI = `
|
commentUI = `
|
||||||
<div class="item-comment-container">
|
<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">
|
<div class="item-comment-actions">
|
||||||
<button type="button" class="item-emoji-trigger" title="Emoji">☺</button>
|
<button type="button" class="item-emoji-trigger" title="Emoji">☺</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -204,6 +204,11 @@ export default router => {
|
|||||||
|
|
||||||
const { url: inputUrl, rating, tags: tagsRaw, comment, is_oc, is_shitpost } = req.post || {};
|
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()) {
|
if (!inputUrl || !inputUrl.trim()) {
|
||||||
return res.json({ success: false, msg: 'URL is required' }, 400);
|
return res.json({ success: false, msg: 'URL is required' }, 400);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,11 @@ export const handleUpload = async (req, res, self) => {
|
|||||||
|
|
||||||
const is_shitpost = (parts.is_shitpost === 'true' || parts.is_shitpost === '1');
|
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) {
|
if (!file || !file.data) {
|
||||||
return sendJson(res, { success: false, msg: 'No file provided' }, 400);
|
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
|
// Insert optional first comment
|
||||||
if (comment && comment.length > 0 && comment.length <= 2000) {
|
if (comment && comment.length > 0) {
|
||||||
try {
|
try {
|
||||||
await db`
|
await db`
|
||||||
INSERT INTO comments ${db({
|
INSERT INTO comments ${db({
|
||||||
|
|||||||
@@ -1286,7 +1286,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="comment-input-row">
|
<div class="comment-input-row">
|
||||||
<button id="comment-emoji-trigger" class="emoji-trigger" title="Emoji" type="button">☺</button>
|
<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>
|
<button id="comment-send-btn" disabled><i class="fa-solid fa-paper-plane"></i></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -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">
|
<div class="form-section">
|
||||||
@if(web_url_upload)
|
@if(web_url_upload)
|
||||||
<div class="upload-mode-tabs">
|
<div class="upload-mode-tabs">
|
||||||
@@ -109,7 +109,7 @@
|
|||||||
<div class="form-section global-comment-section">
|
<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>
|
<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">
|
<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 class="input-actions"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user