mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 14:44:31 +00:00
Add extend method in provider prototype
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
0137df7a7e
commit
8bac1b1835
@ -1,5 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
const fse = require('fs-extra');
|
||||
const { join } = require('path');
|
||||
|
||||
/**
|
||||
* An asynchronous bootstrap function that runs before
|
||||
* your application gets started.
|
||||
@ -8,4 +11,17 @@
|
||||
* run jobs, or perform some special logic.
|
||||
*/
|
||||
|
||||
module.exports = () => {};
|
||||
module.exports = async () => {
|
||||
await fse.ensureDir('./public/uploads/sub-folder');
|
||||
|
||||
// example of overriding the upload provider
|
||||
strapi.plugins.upload.provider.extend({
|
||||
async upload(file) {
|
||||
const filePath = `/uploads/sub-folder/${file.hash}${file.ext}`;
|
||||
|
||||
// write file in public/assets folder
|
||||
await fse.writeFile(join(strapi.config.public.path, filePath), file.buffer);
|
||||
file.url = filePath;
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@ -30,7 +30,9 @@ module.exports = async () => {
|
||||
|
||||
const createProvider = ({ provider, providerOptions }) => {
|
||||
try {
|
||||
return require(`strapi-provider-upload-${provider}`).init(providerOptions);
|
||||
const providerInstance = require(`strapi-provider-upload-${provider}`).init(providerOptions);
|
||||
|
||||
return Object.assign(Object.create(baseProvider), providerInstance);
|
||||
} catch (err) {
|
||||
strapi.log.error(err);
|
||||
throw new Error(
|
||||
@ -38,3 +40,15 @@ const createProvider = ({ provider, providerOptions }) => {
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
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');
|
||||
},
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user