47 lines
1.1 KiB
JavaScript
Raw Normal View History

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.
*/
module.exports = async () => {
2018-02-21 17:18:33 +01:00
// set plugin store
const configurator = strapi.store({
2018-02-20 15:57:34 +01:00
type: 'plugin',
2019-04-05 16:11:09 +02:00
name: 'upload',
key: 'settings',
2018-02-20 15:57:34 +01:00
});
strapi.plugins.upload.provider = createProvider(
strapi.plugins.upload.config || {}
);
2019-08-12 15:35:40 +02:00
// if provider config does not exist set one by default
const config = await configurator.get();
2019-08-12 15:35:40 +02:00
if (!config) {
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
};
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}\``
);
}
};