mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-09-08 16:10:35 +02:00
* feat: create folders in ACP uploads #9638 * fix: openapi * test: missing tests * fix: eslint * fix: tests
This commit is contained in:
@@ -14,6 +14,7 @@ const user = require('../user');
|
||||
const groups = require('../groups');
|
||||
const topics = require('../topics');
|
||||
const posts = require('../posts');
|
||||
const slugify = require('../slugify');
|
||||
|
||||
const helpers = require('./helpers');
|
||||
const controllerHelpers = require('../controllers/helpers');
|
||||
@@ -86,3 +87,20 @@ Assert.path = helpers.try(async (req, res, next) => {
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
Assert.folderName = helpers.try(async (req, res, next) => {
|
||||
const folderName = slugify(path.basename(req.body.folderName.trim()));
|
||||
const folderPath = path.join(res.locals.cleanedPath, folderName);
|
||||
|
||||
// slugify removes invalid characters, folderName may become empty
|
||||
if (!folderName) {
|
||||
return controllerHelpers.formatApiResponse(403, res, new Error('[[error:invalid-path]]'));
|
||||
}
|
||||
if (await file.exists(folderPath)) {
|
||||
return controllerHelpers.formatApiResponse(403, res, new Error('[[error:folder-exists]]'));
|
||||
}
|
||||
|
||||
res.locals.folderPath = folderPath;
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user