mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
Signed-off-by: Edaly Ahmed <ahmed.edaly@oyez.fr>
adding getConfig service and casting params before updating database
This commit is contained in:
parent
67f4712fa7
commit
129edd66ee
@ -13,13 +13,7 @@ module.exports = {
|
||||
const uploadService = strapi.plugins.upload.services.upload;
|
||||
|
||||
// Retrieve provider configuration.
|
||||
const config = await strapi
|
||||
.store({
|
||||
environment: strapi.config.environment,
|
||||
type: 'plugin',
|
||||
name: 'upload',
|
||||
})
|
||||
.get({ key: 'provider' });
|
||||
const config = await uploadService.getConfig();
|
||||
|
||||
// Verify if the file upload is enable.
|
||||
if (config.enabled === false) {
|
||||
@ -55,7 +49,7 @@ module.exports = {
|
||||
const buffers = await uploadService.bufferize(files);
|
||||
|
||||
const enhancedFiles = buffers.map(file => {
|
||||
if (parseFloat(file.size) > parseFloat(config.sizeLimit)) {
|
||||
if (file.size > config.sizeLimit) {
|
||||
return ctx.badRequest(null, [
|
||||
{
|
||||
messages: [
|
||||
@ -131,13 +125,19 @@ module.exports = {
|
||||
},
|
||||
|
||||
async updateSettings(ctx) {
|
||||
const {
|
||||
request: { body: newSettings },
|
||||
} = ctx;
|
||||
await strapi
|
||||
.store({
|
||||
environment: ctx.params.environment,
|
||||
type: 'plugin',
|
||||
name: 'upload',
|
||||
})
|
||||
.set({ key: 'provider', value: ctx.request.body });
|
||||
.set({
|
||||
key: 'provider',
|
||||
value: { ...newSettings, sizeLimit: parseFloat(newSettings.sizeLimit) },
|
||||
});
|
||||
|
||||
ctx.send({ ok: true });
|
||||
},
|
||||
|
||||
@ -50,7 +50,7 @@ module.exports = {
|
||||
: '',
|
||||
buffer,
|
||||
mime: stream.type,
|
||||
size: (stream.size / 1000).toFixed(2),
|
||||
size: parseFloat((stream.size / 1000).toFixed(2)),
|
||||
};
|
||||
};
|
||||
|
||||
@ -176,4 +176,15 @@ module.exports = {
|
||||
})
|
||||
);
|
||||
},
|
||||
async getConfig() {
|
||||
const config = await strapi
|
||||
.store({
|
||||
environment: strapi.config.environment,
|
||||
type: 'plugin',
|
||||
name: 'upload',
|
||||
})
|
||||
.get({ key: 'provider' });
|
||||
|
||||
return { ...config, sizeLimit: parseFloat(config.sizeLimit) };
|
||||
},
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user