mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
Merge branch 'master' into fix/mask
This commit is contained in:
commit
a97e96c240
@ -84,8 +84,8 @@ export function* submit() {
|
||||
|
||||
return acc;
|
||||
}, new FormData());
|
||||
|
||||
const id = isCreating ? '' : record.id;
|
||||
|
||||
const id = isCreating ? '' : record.id || record._id;
|
||||
const params = { source };
|
||||
// Change the request helper default headers so we can pass a FormData
|
||||
const headers = {
|
||||
|
@ -8,6 +8,49 @@ module.exports = async (ctx, next) => {
|
||||
|
||||
if (controller && action) {
|
||||
// Redirect to specific controller.
|
||||
if (ctx.request.body.hasOwnProperty('fields') && ctx.request.body.hasOwnProperty('files')) {
|
||||
let {files, fields} = ctx.request.body;
|
||||
|
||||
const parser = (value) => {
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
} catch (e) {
|
||||
// Silent.
|
||||
}
|
||||
|
||||
return _.isArray(value) ? value.map(obj => parser(obj)) : value;
|
||||
};
|
||||
|
||||
fields = Object.keys(fields).reduce((acc, current) => {
|
||||
acc[current] = parser(fields[current]);
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
ctx.request.body = fields;
|
||||
|
||||
await strapi.plugins[source].controllers[controller.toLowerCase()][action](ctx);
|
||||
const resBody = ctx.body;
|
||||
|
||||
await Promise.all(Object.keys(files).map(async field => {
|
||||
ctx.request.body = {
|
||||
files: {
|
||||
files: files[field]
|
||||
},
|
||||
fields: {
|
||||
refId: resBody.id || resBody._id,
|
||||
ref: ctx.params.model,
|
||||
source,
|
||||
field
|
||||
}
|
||||
};
|
||||
|
||||
return strapi.plugins.upload.controllers.upload.upload(ctx);
|
||||
}));
|
||||
|
||||
return ctx.send(resBody);
|
||||
}
|
||||
|
||||
return await strapi.plugins[source].controllers[controller.toLowerCase()][action](ctx);
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,7 @@
|
||||
"users": {
|
||||
"collection": "user",
|
||||
"via": "role",
|
||||
"plugin": "users-permissions",
|
||||
"configurable": false
|
||||
"plugin": "users-permissions"
|
||||
},
|
||||
"permissions": {
|
||||
"collection": "permission",
|
||||
@ -33,4 +32,4 @@
|
||||
"configurable": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -38,6 +38,12 @@
|
||||
"via": "users",
|
||||
"plugin": "users-permissions",
|
||||
"configurable": false
|
||||
},
|
||||
"picture": {
|
||||
"collection": "file",
|
||||
"via": "related",
|
||||
"plugin": "upload"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"collectionName": "users-permissions_user"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user