mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2025-03-04 07:18:50 -07:00
[mastodon-client] Improve link pagination helper function
This commit is contained in:
parent
d8659b5a94
commit
9d59ee09fd
2 changed files with 7 additions and 7 deletions
packages/backend/src/server/api/mastodon
|
@ -198,7 +198,7 @@ export function apiAccountMastodon(router: Router): void {
|
||||||
const followers = await UserConverter.encodeMany(res.data, cache);
|
const followers = await UserConverter.encodeMany(res.data, cache);
|
||||||
|
|
||||||
ctx.body = followers.map((account) => convertAccount(account));
|
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) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -223,7 +223,7 @@ export function apiAccountMastodon(router: Router): void {
|
||||||
const following = await UserConverter.encodeMany(res.data, cache);
|
const following = await UserConverter.encodeMany(res.data, cache);
|
||||||
|
|
||||||
ctx.body = following.map((account) => convertAccount(account));
|
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) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -414,7 +414,7 @@ export function apiAccountMastodon(router: Router): void {
|
||||||
const bookmarks = await NoteConverter.encodeMany(res.data, user, cache);
|
const bookmarks = await NoteConverter.encodeMany(res.data, user, cache);
|
||||||
|
|
||||||
ctx.body = bookmarks.map(s => convertStatus(s));
|
ctx.body = bookmarks.map(s => convertStatus(s));
|
||||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, `v1/bookmarks`);
|
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
@ -438,7 +438,7 @@ export function apiAccountMastodon(router: Router): void {
|
||||||
const favorites = await NoteConverter.encodeMany(res.data, user, cache);
|
const favorites = await NoteConverter.encodeMany(res.data, user, cache);
|
||||||
|
|
||||||
ctx.body = favorites.map(s => convertStatus(s));
|
ctx.body = favorites.map(s => convertStatus(s));
|
||||||
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res, `v1/favourites`);
|
PaginationHelpers.appendLinkPaginationHeader(args, ctx, res);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(e.response.data);
|
console.error(e.response.data);
|
||||||
|
|
|
@ -65,15 +65,15 @@ export class PaginationHelpers {
|
||||||
return reverse ? found.reverse() : found;
|
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 link: string[] = [];
|
||||||
const limit = args.limit ?? 40;
|
const limit = args.limit ?? 40;
|
||||||
if (res.maxId) {
|
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);
|
link.push(l);
|
||||||
}
|
}
|
||||||
if (res.minId) {
|
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);
|
link.push(l);
|
||||||
}
|
}
|
||||||
if (link.length > 0){
|
if (link.length > 0){
|
||||||
|
|
Loading…
Add table
Reference in a new issue