mirror of
https://github.com/strapi/strapi.git
synced 2025-11-09 22:59:14 +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;
|
const uploadService = strapi.plugins.upload.services.upload;
|
||||||
|
|
||||||
// Retrieve provider configuration.
|
// Retrieve provider configuration.
|
||||||
const config = await strapi
|
const config = await uploadService.getConfig();
|
||||||
.store({
|
|
||||||
environment: strapi.config.environment,
|
|
||||||
type: 'plugin',
|
|
||||||
name: 'upload',
|
|
||||||
})
|
|
||||||
.get({ key: 'provider' });
|
|
||||||
|
|
||||||
// Verify if the file upload is enable.
|
// Verify if the file upload is enable.
|
||||||
if (config.enabled === false) {
|
if (config.enabled === false) {
|
||||||
@ -55,7 +49,7 @@ module.exports = {
|
|||||||
const buffers = await uploadService.bufferize(files);
|
const buffers = await uploadService.bufferize(files);
|
||||||
|
|
||||||
const enhancedFiles = buffers.map(file => {
|
const enhancedFiles = buffers.map(file => {
|
||||||
if (parseFloat(file.size) > parseFloat(config.sizeLimit)) {
|
if (file.size > config.sizeLimit) {
|
||||||
return ctx.badRequest(null, [
|
return ctx.badRequest(null, [
|
||||||
{
|
{
|
||||||
messages: [
|
messages: [
|
||||||
@ -131,13 +125,19 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async updateSettings(ctx) {
|
async updateSettings(ctx) {
|
||||||
|
const {
|
||||||
|
request: { body: newSettings },
|
||||||
|
} = ctx;
|
||||||
await strapi
|
await strapi
|
||||||
.store({
|
.store({
|
||||||
environment: ctx.params.environment,
|
environment: ctx.params.environment,
|
||||||
type: 'plugin',
|
type: 'plugin',
|
||||||
name: 'upload',
|
name: 'upload',
|
||||||
})
|
})
|
||||||
.set({ key: 'provider', value: ctx.request.body });
|
.set({
|
||||||
|
key: 'provider',
|
||||||
|
value: { ...newSettings, sizeLimit: parseFloat(newSettings.sizeLimit) },
|
||||||
|
});
|
||||||
|
|
||||||
ctx.send({ ok: true });
|
ctx.send({ ok: true });
|
||||||
},
|
},
|
||||||
|
|||||||
@ -50,7 +50,7 @@ module.exports = {
|
|||||||
: '',
|
: '',
|
||||||
buffer,
|
buffer,
|
||||||
mime: stream.type,
|
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