Merge branch 'file-limit-error'

merge-requests/208/head
fatchan 5 years ago
commit 481a4fc670
  1. 2
      controllers/forms.js
  2. 6
      controllers/forms/makepost.js
  3. 1
      gulp/res/css/style.css
  4. 9
      gulp/res/js/progress.js
  5. 8
      models/forms/makepost.js
  6. 5
      views/includes/filelabel.pug

@ -31,7 +31,7 @@ const express = require('express')
limits: {
totalSize: globalLimits.postFilesSize.max,
fileSize: globalLimits.postFilesSize.max,
files: globalLimits.postFiles.max
//files: globalLimits.postFiles.max
},
limitHandler: uploadLimitFunction,
useTempFiles: true,

@ -8,15 +8,15 @@ const makePost = require(__dirname+'/../../models/forms/makepost.js')
module.exports = async (req, res, next) => {
res.locals.numFiles = Math.min(res.locals.numFiles, res.locals.board.settings.maxFiles)
const errors = [];
// even if force file and message are off, the post must contain one of either.
if ((!req.body.message || req.body.message.length === 0) && res.locals.numFiles === 0) {
errors.push('Posts must include a message or file');
}
if (res.locals.numFiles > res.locals.board.settings.maxFiles) {
errors.push(`Too many files. Max files per post ${res.locals.board.settings.maxFiles < globalLimits.postFiles.max ? 'on this board ' : ''}is ${res.locals.board.settings.maxFiles}`);
}
// check file, subject and message enforcement according to board settings
if (!req.body.subject || req.body.subject.length === 0) {
if (!req.body.thread && res.locals.board.settings.forceThreadSubject) {

@ -261,6 +261,7 @@ p {
padding: 5px;
min-width: 220px;
flex-grow: 1;
flex-direction: column;
}
.banposts .thread {

@ -23,9 +23,10 @@ window.addEventListener('DOMContentLoaded', () => {
const fileInput = document.getElementById('file');
const fileLabel = fileInput.previousSibling;
const fileLabelText = fileLabel.childNodes[0];
let files = [];
const removeFile = (name) => {
const removeFile = (name) => { //unused atm
for(let i = 1; i < fileLabel.childNodes.length; i++) {
const childNode = fileLabel.childNodes[i];
if (childNode.nodeValue === name) {
@ -39,9 +40,9 @@ window.addEventListener('DOMContentLoaded', () => {
//show number of files on new label
const updateFilesText = () => {
if (files.length === 0) {
fileLabel.innerText = 'Upload/Drop/Paste file(s)';
fileLabelText.nodeValue = 'Upload/Drop/Paste file(s)';
} else {
fileLabel.innerText = `${files.length} files selected`;
fileLabelText.nodeValue = `${files.length} files selected`;
//window.URL.createObjectURL(file);
//todo make x marks to remove each one with "removeFile"
}
@ -88,7 +89,7 @@ window.addEventListener('DOMContentLoaded', () => {
//add files to list instead of replacing when regular upload
fileInput.onchange = () => {
fileLabel.innerText = `${fileInput.files.length} files selected`;
fileLabelText.nodeValue = `${fileInput.files.length} files selected`;
const newFiles = fileInput.files;
for (let i = 0; i < newFiles.length; i++) {
files.push(newFiles[i]);

@ -90,14 +90,6 @@ module.exports = async (req, res, next) => {
});
}
}
if (res.locals.numFiles > maxFiles) {
await deleteTempFiles(req).catch(e => console.error);
return dynamicResponse(req, res, 400, 'message', {
'title': 'Bad request',
'message': `Too many files. Max files per post is ${maxFiles}.`,
'redirect': redirect
});
}
//filters
if (res.locals.permLevel > 1) { //global staff bypass filters
const allContents = req.body.name+req.body.message+req.body.subject+req.body.email

@ -1 +1,4 @@
label.jsonly.postform-style.filelabel(for='file') Upload/Drop/Paste file(s)
label.jsonly.postform-style.filelabel(for='file')
| Select/Drop/Paste file(s)
if board != null
small (Max #{board.settings.maxFiles})

Loading…
Cancel
Save