Merge pull request #5487 from strapi/media-lib/refactoring

Media lib/refactoring
This commit is contained in:
Alexandre BODIN 2020-03-12 09:28:23 +01:00 committed by GitHub
commit f2d92e72fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 43 deletions

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);

View File

@ -38,10 +38,6 @@
"configurable": false,
"required": true
},
"sha256": {
"type": "string",
"configurable": false
},
"ext": {
"type": "string",
"configurable": false

View File

@ -32,7 +32,6 @@ module.exports = {
name: usedName,
alternativeText: fileInfo.alternativeText,
caption: fileInfo.caption,
// sha256: niceHash(buffer),
hash: generateFileName(usedName),
ext,
mime: type,