mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
refactor: show simple error if path doesn't exist
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const nconf = require('nconf');
|
const nconf = require('nconf');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const winston = require('winston');
|
||||||
const sanitizeHtml = require('sanitize-html');
|
const sanitizeHtml = require('sanitize-html');
|
||||||
|
|
||||||
const meta = require('../../meta');
|
const meta = require('../../meta');
|
||||||
@@ -23,8 +24,14 @@ uploadsController.get = async function (req, res, next) {
|
|||||||
}
|
}
|
||||||
const itemsPerPage = 20;
|
const itemsPerPage = 20;
|
||||||
const page = parseInt(req.query.page, 10) || 1;
|
const page = parseInt(req.query.page, 10) || 1;
|
||||||
|
let files = [];
|
||||||
|
try {
|
||||||
|
files = await fs.promises.readdir(currentFolder);
|
||||||
|
} catch (err) {
|
||||||
|
winston.error(err.stack);
|
||||||
|
return next(new Error('[[error:invalid-path]]'));
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
let files = await fs.promises.readdir(currentFolder);
|
|
||||||
files = files.filter(filename => filename !== '.gitignore');
|
files = files.filter(filename => filename !== '.gitignore');
|
||||||
const itemCount = files.length;
|
const itemCount = files.length;
|
||||||
const start = Math.max(0, (page - 1) * itemsPerPage);
|
const start = Math.max(0, (page - 1) * itemsPerPage);
|
||||||
|
|||||||
Reference in New Issue
Block a user