mirror of
https://github.com/strapi/strapi.git
synced 2025-07-21 07:57:45 +00:00
48 lines
970 B
JavaScript
48 lines
970 B
JavaScript
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
|
|
module.exports = {
|
|
async find(ctx) {
|
|
const method = _.has(ctx.query, '_q') ? 'search' : 'fetchAll';
|
|
|
|
ctx.body = await strapi.plugins.upload.services.upload[method](ctx.query);
|
|
},
|
|
|
|
async findOne(ctx) {
|
|
const {
|
|
params: { id },
|
|
} = ctx;
|
|
|
|
const data = await strapi.plugins.upload.services.upload.fetch({ id });
|
|
|
|
if (!data) {
|
|
return ctx.notFound('file.notFound');
|
|
}
|
|
|
|
ctx.body = data;
|
|
},
|
|
|
|
async count(ctx) {
|
|
const method = _.has(ctx.query, '_q') ? 'countSearch' : 'count';
|
|
|
|
ctx.body = await strapi.plugins.upload.services.upload[method](ctx.query);
|
|
},
|
|
|
|
async destroy(ctx) {
|
|
const {
|
|
params: { id },
|
|
} = ctx;
|
|
|
|
const file = await strapi.plugins['upload'].services.upload.fetch({ id });
|
|
|
|
if (!file) {
|
|
return ctx.notFound('file.notFound');
|
|
}
|
|
|
|
await strapi.plugins['upload'].services.upload.remove(file);
|
|
|
|
ctx.body = file;
|
|
},
|
|
};
|