mirror of https://gitgud.io/fatchan/jschan.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
'use strict';
|
|
|
|
const addCustomPage = require(__dirname+'/../../models/forms/addcustompage.js')
|
|
, { CustomPages } = require(__dirname+'/../../db/')
|
|
, dynamicResponse = require(__dirname+'/../../helpers/dynamic.js')
|
|
, { globalLimits } = require(__dirname+'/../../configs/main.js');
|
|
|
|
module.exports = async (req, res, next) => {
|
|
|
|
const errors = [];
|
|
|
|
if (!req.body.message || res.locals.messageLength === 0) {
|
|
errors.push('Missing message');
|
|
}
|
|
if (res.locals.messageLength > globalLimits.customPages.maxLength) {
|
|
errors.push(`Message must be ${globalLimits.customPages.maxLength} characters or less`);
|
|
}
|
|
if (!req.body.title || req.body.title.length === 0) {
|
|
errors.push('Missing title');
|
|
}
|
|
if (req.body.title.length > 50) {
|
|
errors.push('Title must be 50 characters or less');
|
|
}
|
|
if (!req.body.page
|
|
|| req.body.page.length === 0) {
|
|
errors.push('Missing .html name');
|
|
}
|
|
if (/[a-z0-9_-]+/.test(req.body.page) !== true) {
|
|
errors.push('.html name must contain a-z 0-9 _ - only');
|
|
}
|
|
if (req.body.title.length > 50) {
|
|
errors.push('.html name must be 50 characters or less');
|
|
}
|
|
if ((await CustomPages.boardCount(req.params.board)) > globalLimits.customPages.max) {
|
|
errors.push(`Can only create ${globalLimits.customPages.max} pages per board`);
|
|
}
|
|
if ((await CustomPages.findOne(req.params.board, req.body.page))) {
|
|
errors.push('.html name must be unique');
|
|
}
|
|
|
|
if (errors.length > 0) {
|
|
return dynamicResponse(req, res, 400, 'message', {
|
|
'title': 'Bad request',
|
|
'errors': errors,
|
|
'redirect': `/${req.params.booard}/manage/custompages.html`
|
|
});
|
|
}
|
|
|
|
try {
|
|
await addCustomPage(req, res, next);
|
|
} catch (err) {
|
|
return next(err);
|
|
}
|
|
|
|
}
|
|
|