feat: create folders in ACP uploads #9638 (#9750)

* feat: create folders in ACP uploads #9638

* fix: openapi

* test: missing tests

* fix: eslint

* fix: tests
This commit is contained in:
gasoved
2021-08-31 16:27:00 +03:00
committed by GitHub
parent f2028d7009
commit 3df79683f5
11 changed files with 200 additions and 13 deletions

View File

@@ -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();
});