Fix timelines

This commit is contained in:
Jesse Wierzbinski 2023-11-26 12:46:15 -10:00
parent 8c870cdad3
commit 0a74bbfe93
No known key found for this signature in database
7 changed files with 22 additions and 13 deletions

View file

@ -85,7 +85,7 @@ export default async (
}
return jsonResponse(
await Promise.all(objects.map(status => statusToAPI(status))),
await Promise.all(objects.map(status => statusToAPI(status, user))),
200,
{
Link: linkHeader.join(", "),

View file

@ -49,10 +49,10 @@ export default async (
return jsonResponse({
ancestors: await Promise.all(
ancestors.map(status => statusToAPI(status))
ancestors.map(status => statusToAPI(status, user || undefined))
),
descendants: await Promise.all(
descendants.map(status => statusToAPI(status))
descendants.map(status => statusToAPI(status, user || undefined))
),
});
};

View file

@ -61,7 +61,7 @@ export default async (
return jsonResponse(
{
...(await statusToAPI(status)),
...(await statusToAPI(status, user)),
// TODO: Add
// text: Add source text
// poll: Add source poll

View file

@ -78,17 +78,15 @@ export default async (req: Request): Promise<Response> => {
if (objects.length > 0) {
const urlWithoutQuery = req.url.split("?")[0];
linkHeader.push(
`<${urlWithoutQuery}?max_id=${objects[0].id}&limit=${limit}>; rel="next"`
);
linkHeader.push(
`<${urlWithoutQuery}?since_id=${
objects[objects.length - 1].id
}&limit=${limit}>; rel="prev"`
`<${urlWithoutQuery}?max_id=${objects.at(-1)?.id}>; rel="next"`,
`<${urlWithoutQuery}?min_id=${objects[0].id}>; rel="prev"`
);
}
return jsonResponse(
await Promise.all(objects.map(async status => statusToAPI(status))),
await Promise.all(
objects.map(async status => statusToAPI(status, user))
),
200,
{
Link: linkHeader.join(", "),

View file

@ -3,6 +3,7 @@ import { parseRequest } from "@request";
import { errorResponse, jsonResponse } from "@response";
import { client } from "~database/datasource";
import { statusAndUserRelations, statusToAPI } from "~database/entities/Status";
import { getFromRequest } from "~database/entities/User";
import type { APIRouteMeta } from "~types/api";
export const meta: APIRouteMeta = applyConfig({
@ -18,6 +19,7 @@ export const meta: APIRouteMeta = applyConfig({
});
export default async (req: Request): Promise<Response> => {
const { user } = await getFromRequest(req);
const {
local,
limit = 20,
@ -81,7 +83,9 @@ export default async (req: Request): Promise<Response> => {
}
return jsonResponse(
await Promise.all(objects.map(async status => statusToAPI(status))),
await Promise.all(
objects.map(async status => statusToAPI(status, user || undefined))
),
200,
{
Link: linkHeader.join(", "),