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
|
|
|
|
2019-08-12 15:35:40 +02:00
|
|
|
module.exports = async () => {
|
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-05-06 16:01:18 +02:00
|
|
|
const installedProviders = Object.keys(strapi.config.info.dependencies)
|
|
|
|
.filter(d => d.startsWith('strapi-provider-upload-'))
|
|
|
|
.concat('strapi-provider-upload-local');
|
2018-02-20 15:57:34 +01:00
|
|
|
|
2019-05-06 16:01:18 +02:00
|
|
|
for (let installedProvider of _.uniq(installedProviders)) {
|
2019-05-03 14:41:09 +02:00
|
|
|
strapi.plugins.upload.config.providers.push(require(installedProvider));
|
2019-04-05 16:11:09 +02:00
|
|
|
}
|
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
|
|
|
|
const config = await pluginStore.get({ key: 'provider' });
|
|
|
|
|
|
|
|
if (!config) {
|
|
|
|
const provider = _.find(strapi.plugins.upload.config.providers, {
|
|
|
|
provider: 'local',
|
|
|
|
});
|
|
|
|
|
|
|
|
const value = _.assign({}, provider, {
|
|
|
|
enabled: true,
|
|
|
|
// by default limit size to 1 GB
|
|
|
|
sizeLimit: 1000000,
|
|
|
|
});
|
|
|
|
|
|
|
|
await pluginStore.set({ key: 'provider', value });
|
2019-04-05 16:11:09 +02:00
|
|
|
}
|
2018-02-20 15:57:34 +01:00
|
|
|
};
|