diff --git a/src/controllers/admin/uploads.js b/src/controllers/admin/uploads.js index a8762a3500..1ef24c0fc6 100644 --- a/src/controllers/admin/uploads.js +++ b/src/controllers/admin/uploads.js @@ -243,7 +243,7 @@ async function uploadImage(filename, folder, uploadedFile, req, res, next) { let imageData; try { if (plugins.hasListeners('filter:uploadImage')) { - imageData = await plugins.fireHook('filter:uploadImage', { image: uploadedFile, uid: req.uid }); + imageData = await plugins.fireHook('filter:uploadImage', { image: uploadedFile, uid: req.uid, folder: folder }); } else { imageData = await file.saveFileToLocal(filename, folder, uploadedFile.path); } diff --git a/src/controllers/uploads.js b/src/controllers/uploads.js index efb93c196e..54cd36f603 100644 --- a/src/controllers/uploads.js +++ b/src/controllers/uploads.js @@ -64,6 +64,7 @@ async function uploadAsImage(req, uploadedFile) { return await plugins.fireHook('filter:uploadImage', { image: uploadedFile, uid: req.uid, + folder: 'files', }); } await image.isFileTypeAllowed(uploadedFile.path); @@ -129,6 +130,7 @@ uploadsController.uploadThumb = async function (req, res, next) { return await plugins.fireHook('filter:uploadImage', { image: uploadedFile, uid: req.uid, + folder: 'files', }); } @@ -141,6 +143,7 @@ uploadsController.uploadFile = async function (uid, uploadedFile) { return await plugins.fireHook('filter:uploadFile', { file: uploadedFile, uid: uid, + folder: 'files', }); } @@ -159,16 +162,16 @@ uploadsController.uploadFile = async function (uid, uploadedFile) { throw new Error('[[error:invalid-file-type, ' + allowed.join(', ') + ']]'); } - return await saveFileToLocal(uid, uploadedFile); + return await saveFileToLocal(uid, 'files', uploadedFile); }; -async function saveFileToLocal(uid, uploadedFile) { +async function saveFileToLocal(uid, folder, uploadedFile) { const name = uploadedFile.name || 'upload'; const extension = path.extname(name) || ''; const filename = Date.now() + '-' + validator.escape(name.substr(0, name.length - extension.length)).substr(0, 255) + extension; - const upload = await file.saveFileToLocal(filename, 'files', uploadedFile.path); + const upload = await file.saveFileToLocal(filename, folder, uploadedFile.path); const storedFile = { url: nconf.get('relative_path') + upload.url, path: upload.path, diff --git a/src/image.js b/src/image.js index b39373f861..4bf588621c 100644 --- a/src/image.js +++ b/src/image.js @@ -149,6 +149,7 @@ image.uploadImage = async function (filename, folder, imageData) { return await plugins.fireHook('filter:uploadImage', { image: imageData, uid: imageData.uid, + folder: folder, }); } await image.isFileTypeAllowed(imageData.path); diff --git a/src/topics/thumb.js b/src/topics/thumb.js index 33b750e7c0..356be5b4a3 100644 --- a/src/topics/thumb.js +++ b/src/topics/thumb.js @@ -40,7 +40,8 @@ module.exports = function (Topics) { extension = '.' + mime.getExtension(type); } const filename = Date.now() + '-topic-thumb' + extension; - pathToUpload = path.join(nconf.get('upload_path'), 'files', filename); + const folder = 'files'; + pathToUpload = path.join(nconf.get('upload_path'), folder, filename); await pipeToFileAsync(data.thumb, pathToUpload); @@ -53,11 +54,15 @@ module.exports = function (Topics) { }); if (!plugins.hasListeners('filter:uploadImage')) { - data.thumb = '/assets/uploads/files/' + filename; + data.thumb = '/assets/uploads/' + folder + '/' + filename; return; } - const uploadedFile = await plugins.fireHook('filter:uploadImage', { image: { path: pathToUpload, name: '' }, uid: data.uid }); + const uploadedFile = await plugins.fireHook('filter:uploadImage', { + image: { path: pathToUpload, name: '' }, + uid: data.uid, + folder: folder, + }); file.delete(pathToUpload); data.thumb = uploadedFile.url; } catch (err) {