Merge pull request #12997 from strapi/revert-12838-fix/upload-actionOptions

Revert "Fix actionOptions not taking into account by the upload provider"
This commit is contained in:
Gustav Hansen 2022-03-29 12:30:27 +02:00 committed by GitHub
commit 8b65a9501f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,35 +49,27 @@ const createProvider = config => {
const providerInstance = provider.init(providerOptions);
if (!providerInstance.delete) {
throw new Error(`The upload provider "${providerName}" doesn't implement the delete method.`);
}
if (!providerInstance.upload && !providerInstance.uploadStream) {
throw new Error(
`The upload provider "${providerName}" doesn't implement the uploadStream nor the upload method.`
);
}
if (!providerInstance.uploadStream) {
process.emitWarning(
`The upload provider "${providerName}" doesn't implement the uploadStream function. Strapi will fallback on the upload method. Some performance issues may occur.`
);
}
const wrappedProvider = _.mapValues(providerInstance, (method, methodName) => {
return async function(file, options = actionOptions[methodName]) {
return providerInstance[methodName](file, options);
};
return Object.assign(Object.create(baseProvider), {
...providerInstance,
upload(file, options = actionOptions.upload) {
return providerInstance.upload(file, options);
},
delete(file, options = actionOptions.delete) {
return providerInstance.delete(file, options);
},
});
return Object.assign(Object.create(baseProvider), wrappedProvider);
};
const baseProvider = {
extend(obj) {
Object.assign(this, obj);
},
upload() {
throw new Error('Provider upload method is not implemented');
},
delete() {
throw new Error('Provider delete method is not implemented');
},
};
const registerPermissionActions = async () => {