Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
Alexandre Bodin 2020-03-09 11:05:18 +01:00
parent f9d924dd47
commit 2b5c332e09

View File

@ -89,44 +89,6 @@ module.exports = {
ctx.body = { data };
},
async replaceFile(ctx) {
const { id } = ctx.params;
const uploadService = strapi.plugins.upload.services.upload;
// Retrieve provider configuration.
const { enabled } = strapi.plugins.upload.config;
// Verify if the file upload is enable.
if (enabled === false) {
throw strapi.errors.badRequest(null, {
errors: [{ id: 'Upload.status.disabled', message: 'File upload is disabled' }],
});
}
const data = await strapi.plugins['upload'].services.upload.fetch({ id });
if (!data) {
return ctx.notFound('file.notFound');
}
const { fileInfo } = await validateUploadBody(uploadSchema, ctx.request.body);
const { file = {} } = ctx.request.files || {};
if (_.isUndefined(file)) {
throw strapi.errors.badRequest(null, {
errors: [{ id: 'Upload.status.empty', message: 'File is missing' }],
});
}
const enhancedFile = uploadService.enhanceFile(file, fileInfo);
const updatedFile = await uploadService.update(id, enhancedFile);
ctx.body = updatedFile;
},
async find(ctx) {
const data = await strapi.plugins['upload'].services.upload.fetchAll(ctx.query);