103 lines
2.6 KiB
JavaScript
Raw Normal View History

2021-07-08 11:20:13 +02:00
'use strict';
2022-07-07 21:20:53 +02:00
const { getService } = require('./utils');
const { ALLOWED_SORT_STRINGS } = require('./constants');
2022-07-07 21:20:53 +02:00
module.exports = async ({ strapi }) => {
2022-12-12 10:05:22 +00:00
const defaultConfig = {
settings: {
sizeOptimization: true,
responsiveDimensions: true,
autoOrientation: false,
},
view_configuration: {
pageSize: 10,
sort: ALLOWED_SORT_STRINGS[0],
},
};
for (const [key, defaultValue] of Object.entries(defaultConfig)) {
// set plugin store
const configurator = strapi.store({ type: 'plugin', name: 'upload', key });
const config = await configurator.get();
if (
config &&
Object.keys(defaultValue).every((key) => Object.prototype.hasOwnProperty.call(config, key))
) {
continue;
}
2022-12-12 10:05:22 +00:00
// if the config does not exist or does not have all the required keys
// set from the defaultValue ensuring all required settings are present
await configurator.set({
2022-12-12 10:05:22 +00:00
value: Object.assign(defaultValue, config || {}),
2021-08-19 16:49:33 +02:00
});
}
await registerPermissionActions();
2022-07-07 21:20:53 +02:00
2023-03-15 14:37:31 +01:00
await getService('weeklyMetrics').registerCron();
getService('metrics').sendUploadPluginMetrics();
2023-04-27 11:53:49 +02:00
if (strapi.config.get('plugin.upload.signAdminURLsOnly', false)) {
getService('extensions').contentManager.entityManager.addSignedFileUrlsToAdmin();
} else {
getService('extensions').core.entityService.addSignedFileUrlsToEntityService();
}
2021-08-19 16:49:33 +02:00
};
const registerPermissionActions = async () => {
const actions = [
{
section: 'plugins',
displayName: 'Access the Media Library',
uid: 'read',
pluginName: 'upload',
},
{
section: 'plugins',
displayName: 'Create (upload)',
uid: 'assets.create',
subCategory: 'assets',
pluginName: 'upload',
},
{
section: 'plugins',
displayName: 'Update (crop, details, replace) + delete',
uid: 'assets.update',
subCategory: 'assets',
pluginName: 'upload',
},
{
section: 'plugins',
displayName: 'Download',
uid: 'assets.download',
subCategory: 'assets',
pluginName: 'upload',
},
{
section: 'plugins',
displayName: 'Copy link',
uid: 'assets.copy-link',
subCategory: 'assets',
pluginName: 'upload',
},
{
section: 'plugins',
displayName: 'Configure view',
uid: 'configure-view',
pluginName: 'upload',
},
2021-08-19 16:49:33 +02:00
{
section: 'settings',
displayName: 'Access the Media Library settings page',
uid: 'settings.read',
category: 'media library',
pluginName: 'upload',
},
];
await strapi.admin.services.permission.actionProvider.registerMany(actions);
};