2018-02-08 12:01:06 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upload.js controller
|
|
|
|
*
|
|
|
|
* @description: A set of functions called "actions" of the `upload` plugin.
|
|
|
|
*/
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default action.
|
|
|
|
*
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
|
|
|
|
index: async (ctx) => {
|
2018-02-19 14:26:20 +01:00
|
|
|
const Service = strapi.plugins['upload'].services.upload;
|
|
|
|
|
2018-02-19 15:41:26 +01:00
|
|
|
const files = await Service.buffurize(ctx.request.body.files);
|
2018-02-19 14:26:20 +01:00
|
|
|
|
|
|
|
await Service.upload(files);
|
2018-02-08 12:01:06 +01:00
|
|
|
|
|
|
|
// Send 200 `ok`
|
2018-02-19 14:26:20 +01:00
|
|
|
ctx.send(files.map((file) => {
|
2018-02-19 15:41:26 +01:00
|
|
|
delete file.buffer;
|
|
|
|
file.url = `${strapi.config.url}/uploads/${file.hash}.${file.ext}`;
|
|
|
|
|
|
|
|
// Static data
|
|
|
|
file.updatedAt = new Date();
|
|
|
|
file.relatedTo = 'John Doe';
|
|
|
|
|
|
|
|
return file;
|
2018-02-19 14:26:20 +01:00
|
|
|
}));
|
2018-02-19 15:41:26 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
find: async (ctx) => {
|
|
|
|
const data = await strapi.plugins['upload'].services.upload.fetchAll(ctx.query);
|
|
|
|
|
|
|
|
// Send 200 `ok`
|
2018-02-19 16:00:37 +01:00
|
|
|
ctx.send(data.map((file) => {
|
|
|
|
file.url = `${strapi.config.url}${file.url}`;
|
|
|
|
return file;
|
|
|
|
}));
|
2018-02-19 15:41:26 +01:00
|
|
|
},
|
2018-02-19 16:00:37 +01:00
|
|
|
|
2018-02-19 19:54:45 +01:00
|
|
|
count: async (ctx, next) => {
|
|
|
|
const data = await strapi.plugins['upload'].services.upload.count(ctx.query);
|
|
|
|
|
|
|
|
// Send 200 `ok`
|
|
|
|
ctx.send({
|
|
|
|
count: data
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-02-19 16:00:37 +01:00
|
|
|
destroy: async (ctx, next) => {
|
|
|
|
const data = await strapi.plugins['upload'].services.upload.remove(ctx.params);
|
|
|
|
|
|
|
|
// Send 200 `ok`
|
|
|
|
ctx.send(data);
|
|
|
|
}
|
2018-02-08 12:01:06 +01:00
|
|
|
};
|