add shitpost mode config options

This commit is contained in:
2026-05-23 22:38:28 +02:00
parent e61654c567
commit 9a9b787fd7
5 changed files with 61 additions and 21 deletions

View File

@@ -1077,6 +1077,8 @@ process.on('uncaughtException', err => {
registration_web_toggle_enabled: cfg.websrv.open_registration_web_toggle !== false,
get trusted_uploads() { return getTrustedUploads(); },
get shitpost_mode() { return getShitpostMode(); },
shitpost_require_rating: !!cfg.websrv.shitpost_require_rating,
shitpost_min_tags: parseInt(cfg.websrv.shitpost_min_tags) || 0,
get about_text() { return getAboutText(); },
get rules_text() { return getRulesText(); },
get terms_text() { return getTermsText(); },

View File

@@ -119,23 +119,32 @@ export const handleUpload = async (req, res, self) => {
return sendJson(res, { success: false, msg: 'No file provided' }, 400);
}
// In shitpost mode, rating is optional — null means no rating tag is assigned (truly untagged)
const effectiveRating = (rating && ['sfw', 'nsfw', 'nsfl'].includes(rating)) ? rating : (is_shitpost ? null : null);
// In shitpost mode, rating is optional — null means no rating tag is assigned (truly untagged).
// If shitpost_require_rating is configured to true, a rating is strictly required.
const effectiveRating = (rating && ['sfw', 'nsfw', 'nsfl'].includes(rating)) ? rating : null;
if (!is_shitpost && !effectiveRating) {
return sendJson(res, { success: false, msg: 'Rating (sfw/nsfw/nsfl) is required' }, 400);
}
if (is_shitpost && cfg.websrv.shitpost_require_rating === true && !effectiveRating) {
return sendJson(res, { success: false, msg: 'Rating (sfw/nsfw/nsfl) is required for each item' }, 400);
}
if (effectiveRating === 'nsfl' && !cfg.enable_nsfl) {
return sendJson(res, { success: false, msg: 'NSFL mode is currently disabled' }, 400);
}
const tags = tagsRaw ? tagsRaw.split(',').map(t => t.trim()).filter(t => t.length > 0 && !['sfw', 'nsfw', 'nsfl'].includes(t.toLowerCase())) : [];
const minTags = getMinTags();
// In shitpost mode, tags are optional — items without tags enter as untagged
// In shitpost mode, tags are optional by default — unless shitpost_min_tags is configured.
const shitpostMinTags = is_shitpost ? (parseInt(cfg.websrv.shitpost_min_tags) || 0) : 0;
if (!is_shitpost && tags.length < minTags) {
return sendJson(res, { success: false, msg: `At least ${minTags} tags are required` }, 400);
}
if (is_shitpost && shitpostMinTags > 0 && tags.length < shitpostMinTags) {
return sendJson(res, { success: false, msg: `At least ${shitpostMinTags} tag${shitpostMinTags !== 1 ? 's' : ''} are required` }, 400);
}
// Validate MIME type
const allowedMimes = Object.keys(cfg.mimes);