2018-02-20 15:57:34 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An asynchronous bootstrap function that runs before
|
|
|
|
* your application gets started.
|
|
|
|
*
|
|
|
|
* This gives you an opportunity to set up your data model,
|
|
|
|
* run jobs, or perform some special logic.
|
|
|
|
*/
|
|
|
|
|
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-02-27 19:34:14 +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,
|
|
|
|
videoPreview: 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}\``
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|