diff --git a/gulp/res/css/style.css b/gulp/res/css/style.css index ac9bd0f9..1630b724 100644 --- a/gulp/res/css/style.css +++ b/gulp/res/css/style.css @@ -896,6 +896,14 @@ input:invalid, textarea:invalid { min-height: 100px; } +.board-flag { + margin: 5px; + max-width: 100%; + border: 1px solid var(--post-outline-color); + width: 32px; + height: 22px; +} + .board-description { text-align:center; margin: 0; diff --git a/helpers/filemiddlewares.js b/helpers/filemiddlewares.js index faa377d2..1fdd0e8b 100644 --- a/helpers/filemiddlewares.js +++ b/helpers/filemiddlewares.js @@ -8,10 +8,13 @@ const { debugLogs } = require(__dirname+'/../configs/secrets.js') let postFiles, uploadLimitFunction, handleBannerFiles, + handleFlagFiles, numFilesUploadLimitFunction, + numFlagsUploadLimitFunction, numBannersUploadLimitFunction; const updateHandlers = () => { + //this thing is kinda gross const { globalLimits, filterFileNames, spaceFileNameReplacement } = require(__dirname+'/../config.js').get uploadLimitFunction = (req, res, next) => { return dynamicResponse(req, res, 413, 'message', { @@ -35,6 +38,13 @@ const updateHandlers = () => { 'redirect': req.headers.referer }); }; + numFlagsUploadLimitFunction = (req, res, next) => { + return dynamicResponse(req, res, 400, 'message', { + 'title': 'Too many files', + 'message': `Max banners per request is ${globalLimits.flagFiles.max}`, + 'redirect': req.headers.referer + }); + }; handleBannerFiles = upload({ debug: debugLogs, createParentPath: true, @@ -52,6 +62,23 @@ const updateHandlers = () => { tempFileDir: __dirname+'/../tmp/' }); module.exports.handleBannerFiles = handleBannerFiles; + handleFlagFiles = upload({ + debug: debugLogs, + createParentPath: true, + safeFileNames: filterFileNames, + spaceFileNameReplacement, + preserveExtension: 4, + limits: { + totalSize: globalLimits.flagFilesSize.max, + fileSize: globalLimits.flagFilesSize.max, + files: globalLimits.flagFiles.max + }, + numFilesLimitHandler: numFlagsUploadLimitFunction, + limitHandler: uploadLimitFunction, + useTempFiles: true, + tempFileDir: __dirname+'/../tmp/' + }); + module.exports.handleFlagFiles = handleFlagFiles; postFiles = upload({ debug: debugLogs, createParentPath: true, @@ -76,6 +103,7 @@ addCallback('config', updateHandlers); module.exports = { handleBannerFiles, + handleFlagFiles, handlePostFilesEarlyTor: (req, res, next) => { if (res.locals.anonymizer) { diff --git a/helpers/paramconverter.js b/helpers/paramconverter.js index cbbe0309..c94b81f5 100644 --- a/helpers/paramconverter.js +++ b/helpers/paramconverter.js @@ -3,7 +3,7 @@ const { ObjectId } = require(__dirname+'/../db/db.js') //todo: separate these into a schema/set for differ ent routes and inject it before the controller, to prevent checkign a bunch of other shit for every post , allowedArrays = new Set(['captcha', 'checkedcustompages', 'checkednews', 'checkedposts', 'globalcheckedposts', 'spoiler', 'strip_filename', - 'checkedreports', 'checkedbans', 'checkedbanners', 'checkedaccounts', 'countries']) + 'checkedreports', 'checkedbans', 'checkedbanners', 'checkedaccounts', 'checkedflags', 'countries']) , trimFields = ['allowed_hosts', 'dnsbl_blacklists', 'other_mime_types', 'highlight_options_language_subset', 'themes', 'code_themes', 'global_limits_custom_css_filters', 'board_defaults_filters', 'filters', 'tags', 'uri', 'moderators', 'announcement', 'description', 'message', 'name', 'subject', 'email', 'postpassword', 'password', 'default_name', 'report_reason', 'ban_reason', 'log_message', 'custom_css'] //trim if we dont want filed with whitespace diff --git a/views/mixins/fileform.pug b/views/mixins/fileform.pug index 1c600299..551196ac 100644 --- a/views/mixins/fileform.pug +++ b/views/mixins/fileform.pug @@ -1,10 +1,10 @@ include ./filelabel.pug -mixin fileform(name, max, total, addpath, deletepath, checkname, fileList) +mixin fileform(name, max, total, addPath, deletePath, checkName, fileList, filePath, imageClass) - const capitalName = `${name.charAt(0).toUpperCase()}${name.substring(1)}`; h4.no-m-p Add #{capitalName}s (Max #{globalLimits.bannerFiles.total}) .form-wrapper.flexleft.mt-10 - form.form-post(action=addpath, enctype='multipart/form-data', method='POST') + form.form-post(action=addPath, enctype='multipart/form-data', method='POST') input(type='hidden' name='_csrf' value=csrf) .row .label @@ -23,11 +23,11 @@ mixin fileform(name, max, total, addpath, deletepath, checkname, fileList) hr(size=1) h4.no-m-p Delete #{capitalName}s: .form-wrapper.flexleft.mt-10 - form.form-post(action=deletepath, enctype='application/x-www-form-urlencoded', method='POST') + form.form-post(action=deletePath, enctype='application/x-www-form-urlencoded', method='POST') input(type='hidden' name='_csrf' value=csrf) .catalog each file in fileList label.banner-check - input(type='checkbox' name=checkname value=file) - img.board-banner(src=`${filepath}/${file}` loading='lazy') + input(type='checkbox' name=checkName value=file) + img(class=imageClass src=`${filePath}/${file}` loading='lazy') input(type='submit', value='delete') diff --git a/views/pages/manageassets.pug b/views/pages/manageassets.pug index e5d47d5c..15a7443c 100644 --- a/views/pages/manageassets.pug +++ b/views/pages/manageassets.pug @@ -13,10 +13,10 @@ block content hr(size=1) +fileform('banner', globalLimits.bannerFiles.max, globalLimits.bannerFiles.total, `/forms/board/${board._id}/addbanners`, `/forms/board/${board._id}/deletebanners`, - 'checkedbanners', board.banners) + 'checkedbanners', board.banners, `/banners/${board._id}`, 'board-banner') hr(size=1) +fileform('flag', globalLimits.flagFiles.max, globalLimits.flagFiles.total, `/forms/board/${board._id}/addflags`, `/forms/board/${board._id}/deleteflags`, - 'checkedflags', board.flags) + 'checkedflags', board.flags, `/flag/${board._id}`, 'board-flag') hr(size=1) p todo: custom other files