mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-22 00:43:49 +01:00
[mastodon-client] Improve link pagination helper function
This commit is contained in:
parent
d8659b5a94
commit
9d59ee09fd
@ -198,7 +198,7 @@ export function apiAccountMastodon(router: Router): void {
|
||||
const followers = await UserConverter.encodeMany(res.data, cache);
|
||||
|
||||
ctx.body = followers.map((account) => convertAccount(account));
|
||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, `v1/accounts/${ctx.params.id}/followers`);
|
||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
@ -223,7 +223,7 @@ export function apiAccountMastodon(router: Router): void {
|
||||
const following = await UserConverter.encodeMany(res.data, cache);
|
||||
|
||||
ctx.body = following.map((account) => convertAccount(account));
|
||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, `v1/accounts/${ctx.params.id}/following`);
|
||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
@ -414,7 +414,7 @@ export function apiAccountMastodon(router: Router): void {
|
||||
const bookmarks = await NoteConverter.encodeMany(res.data, user, cache);
|
||||
|
||||
ctx.body = bookmarks.map(s => convertStatus(s));
|
||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, `v1/bookmarks`);
|
||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
@ -438,7 +438,7 @@ export function apiAccountMastodon(router: Router): void {
|
||||
const favorites = await NoteConverter.encodeMany(res.data, user, cache);
|
||||
|
||||
ctx.body = favorites.map(s => convertStatus(s));
|
||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, `v1/favourites`);
|
||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
console.error(e.response.data);
|
||||
|
@ -65,15 +65,15 @@ export class PaginationHelpers {
|
||||
return reverse ? found.reverse() : found;
|
||||
}
|
||||
|
||||
public static appendLinkPaginationHeader(args: any, ctx: any, res: any, route: string): void {
|
||||
public static appendLinkPaginationHeader(args: any, ctx: any, res: any): void {
|
||||
const link: string[] = [];
|
||||
const limit = args.limit ?? 40;
|
||||
if (res.maxId) {
|
||||
const l = `<${config.url}/api/${route}?limit=${limit}&max_id=${convertId(res.maxId, IdType.MastodonId)}>; rel="next"`;
|
||||
const l = `<${config.url}/api${ctx.path}?limit=${limit}&max_id=${convertId(res.maxId, IdType.MastodonId)}>; rel="next"`;
|
||||
link.push(l);
|
||||
}
|
||||
if (res.minId) {
|
||||
const l = `<${config.url}/api/${route}?limit=${limit}&min_id=${convertId(res.minId, IdType.MastodonId)}>; rel="prev"`;
|
||||
const l = `<${config.url}/api${ctx.path}?limit=${limit}&min_id=${convertId(res.minId, IdType.MastodonId)}>; rel="prev"`;
|
||||
link.push(l);
|
||||
}
|
||||
if (link.length > 0){
|
||||
|
Loading…
Reference in New Issue
Block a user