63 lines
1.3 KiB
JavaScript
Raw Normal View History

'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;
const files = await Service.buffurize(ctx.request.body.files);
2018-02-19 14:26:20 +01:00
await Service.upload(files);
// Send 200 `ok`
2018-02-19 14:26:20 +01:00
ctx.send(files.map((file) => {
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
}));
},
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 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);
}
};