[mastodon-client] Improve link pagination helper function

This commit is contained in:
Laura Hausmann 2023-09-28 16:51:25 +02:00
parent d8659b5a94
commit 9d59ee09fd
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
2 changed files with 7 additions and 7 deletions

View File

@ -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);

View File

@ -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){