2018-02-20 15:57:34 +01:00
|
|
|
'use strict';
|
|
|
|
/**
|
2020-03-08 16:53:53 +01:00
|
|
|
* Upload plugin bootstrapi.
|
2018-02-20 15:57:34 +01:00
|
|
|
*
|
2020-03-08 16:53:53 +01:00
|
|
|
* It initializes the provider and sets the default settings in db.
|
2018-02-20 15:57:34 +01:00
|
|
|
*/
|
|
|
|
|
2020-02-28 09:06:26 +01:00
|
|
|
module.exports = async () => {
|
2018-02-21 17:18:33 +01:00
|
|
|
// set plugin store
|
2020-02-26 18:34:45 +01:00
|
|
|
const configurator = strapi.store({
|
2018-02-20 15:57:34 +01:00
|
|
|
type: 'plugin',
|
2019-04-05 16:11:09 +02:00
|
|
|
name: 'upload',
|
2020-02-26 18:34:45 +01:00
|
|
|
key: 'settings',
|
2018-02-20 15:57:34 +01:00
|
|
|
});
|
|
|
|
|
2020-03-03 18:35:57 +01:00
|
|
|
strapi.plugins.upload.provider = createProvider(strapi.plugins.upload.config || {});
|
2019-03-01 17:09:19 +01:00
|
|
|
|
2019-08-12 15:35:40 +02:00
|
|
|
// if provider config does not exist set one by default
|
2020-02-26 18:34:45 +01:00
|
|
|
const config = await configurator.get();
|
2019-08-12 15:35:40 +02:00
|
|
|
|
|
|
|
if (!config) {
|
2020-02-26 18:34:45 +01:00
|
|
|
await configurator.set({
|
|
|
|
value: {
|
|
|
|
sizeOptimization: true,
|
|
|
|
responsiveDimensions: true,
|
|
|
|
},
|
2019-08-12 15:35:40 +02:00
|
|
|
});
|
2019-04-05 16:11:09 +02:00
|
|
|
}
|
2018-02-20 15:57:34 +01:00
|
|
|
};
|
2020-02-27 19:34:14 +01:00
|
|
|
|
|
|
|
const createProvider = ({ provider, providerOptions }) => {
|
|
|
|
try {
|
|
|
|
return require(`strapi-provider-upload-${provider}`).init(providerOptions);
|
|
|
|
} catch (err) {
|
|
|
|
strapi.log.error(err);
|
|
|
|
throw new Error(
|
|
|
|
`The provider package isn't installed. Please run \`npm install strapi-provider-upload-${provider}\``
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|