mirror of
https://github.com/strapi/strapi.git
synced 2026-01-06 04:03:25 +00:00
Merge pull request #5487 from strapi/media-lib/refactoring
Media lib/refactoring
This commit is contained in:
commit
f2d92e72fc
@ -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);
|
||||
|
||||
|
||||
@ -38,10 +38,6 @@
|
||||
"configurable": false,
|
||||
"required": true
|
||||
},
|
||||
"sha256": {
|
||||
"type": "string",
|
||||
"configurable": false
|
||||
},
|
||||
"ext": {
|
||||
"type": "string",
|
||||
"configurable": false
|
||||
|
||||
@ -32,7 +32,6 @@ module.exports = {
|
||||
name: usedName,
|
||||
alternativeText: fileInfo.alternativeText,
|
||||
caption: fileInfo.caption,
|
||||
// sha256: niceHash(buffer),
|
||||
hash: generateFileName(usedName),
|
||||
ext,
|
||||
mime: type,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user