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.
|
|
|
|
*/
|
2018-04-30 18:00:01 +02:00
|
|
|
const _ = require('lodash');
|
2018-02-20 15:57:34 +01:00
|
|
|
|
|
|
|
module.exports = async cb => {
|
2018-02-21 17:18:33 +01:00
|
|
|
// set plugin store
|
2018-02-20 15:57:34 +01:00
|
|
|
const pluginStore = strapi.store({
|
|
|
|
environment: strapi.config.environment,
|
|
|
|
type: 'plugin',
|
2019-04-05 16:11:09 +02:00
|
|
|
name: 'upload',
|
2018-02-20 15:57:34 +01:00
|
|
|
});
|
|
|
|
|
2018-03-07 11:26:53 +01:00
|
|
|
strapi.plugins.upload.config.providers = [];
|
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
const installedProviders = Object.keys(
|
|
|
|
strapi.config.info.dependencies
|
|
|
|
).filter(d => d.startsWith('strapi-provider-upload-'));
|
2018-02-20 15:57:34 +01:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
for (let installedProvider of installedProviders) {
|
|
|
|
strapi.plugins.email.config.providers.push(require(installedProvider));
|
|
|
|
}
|
2019-03-01 17:09:19 +01:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
try {
|
|
|
|
// if provider config does not exist set one by default
|
|
|
|
const config = await pluginStore.get({ key: 'provider' });
|
2019-03-01 17:09:19 +01:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
if (!config) {
|
|
|
|
const provider = _.find(strapi.plugins.email.config.providers, {
|
|
|
|
provider: 'local',
|
2018-03-06 15:49:11 +01:00
|
|
|
});
|
2018-02-20 15:57:34 +01:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
const value = _.assign({}, provider, {
|
|
|
|
enabled: true,
|
|
|
|
// by default limit size to 1 GB
|
|
|
|
sizeLimit: 1000000,
|
|
|
|
});
|
2018-03-06 15:49:11 +01:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
await pluginStore.set({ key: 'provider', value });
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
strapi.log.error(err);
|
|
|
|
strapi.stop();
|
|
|
|
}
|
|
|
|
cb();
|
2018-02-20 15:57:34 +01:00
|
|
|
};
|