Fixed 267U.pre2
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import config from "../../../../config/index.js";
|
||||
export async function PaginationMiddleware(ctx, next) {
|
||||
await next();
|
||||
if (!ctx.pagination) return;
|
||||
const link = [];
|
||||
const limit = ctx.pagination.limit;
|
||||
if (ctx.pagination.maxId) {
|
||||
const l = `<${config.url}/api${ctx.path}?limit=${limit}&max_id=${ctx.pagination.maxId}>; rel="next"`;
|
||||
link.push(l);
|
||||
}
|
||||
if (ctx.pagination.minId) {
|
||||
const l = `<${config.url}/api${ctx.path}?limit=${limit}&min_id=${ctx.pagination.minId}>; rel="prev"`;
|
||||
link.push(l);
|
||||
}
|
||||
if (link.length > 0) {
|
||||
ctx.response.append('Link', link.join(', '));
|
||||
}
|
||||
}
|
||||
export function generatePaginationData(ids, limit) {
|
||||
if (ids.length < 1) return undefined;
|
||||
return {
|
||||
limit: limit,
|
||||
maxId: ids.length < limit ? undefined : ids.at(-1),
|
||||
minId: ids.at(0)
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user