Hi guys,
I’m facing the same issue and needed to use pagination[page]&pagination[pageSize].
Here is how I could make it work. The important part is using findPage() instead of findMany().
Hopefully this helps someone.
BTW, I found a related issue for listing users. It would be great to have those plugins following the same standard.
# extensions/upload/strapi-server.js
const { sanitize, validate } = require('@strapi/utils');
const FILE_MODEL_UID = "plugin::upload.file";
const sanitizeOutput = async (data, ctx) => {
const schema = strapi.getModel(FILE_MODEL_UID);
const { auth } = ctx.state;
return sanitize.contentAPI.output(data, schema, { auth });
};
const validateQuery = async (data, ctx) => {
const schema = strapi.getModel(FILE_MODEL_UID);
const { auth } = ctx.state;
return validate.contentAPI.query(data, schema, { auth });
};
const sanitizeQuery = async (data, ctx) => {
const schema = strapi.getModel(FILE_MODEL_UID);
const { auth } = ctx.state;
return sanitize.contentAPI.query(data, schema, { auth });
};
module.exports = (plugin) => {
plugin.controllers["content-api"].find = async (ctx) => {
ctx.query = {...ctx.query, ...ctx.query?.pagination}
await validateQuery(ctx.query, ctx);
const sanitizedQuery = await sanitizeQuery(ctx.query, ctx);
const data = await strapi.plugin("upload").services.upload.findPage(sanitizedQuery);
const {results, pagination} = await sanitizeOutput(data, ctx);
ctx.body = {
data: results,
meta: {
pagination: pagination,
},
};
}
return plugin;
};