40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { z } from "zod";
|
|
import { Fastify } from "../types";
|
|
import { FeedBodySchema } from "@/app/feed/types";
|
|
import { feedGet } from "@/app/feed/feedGet";
|
|
import { Context } from "@/context";
|
|
import { db } from "@/storage/db";
|
|
|
|
export function feedRoutes(app: Fastify) {
|
|
app.get('/v1/feed', {
|
|
preHandler: app.authenticate,
|
|
schema: {
|
|
querystring: z.object({
|
|
before: z.string().optional(),
|
|
after: z.string().optional(),
|
|
limit: z.coerce.number().int().min(1).max(200).default(50)
|
|
}).optional(),
|
|
response: {
|
|
200: z.object({
|
|
items: z.array(z.object({
|
|
id: z.string(),
|
|
body: FeedBodySchema,
|
|
repeatKey: z.string().nullable(),
|
|
cursor: z.string(),
|
|
createdAt: z.number()
|
|
})),
|
|
hasMore: z.boolean()
|
|
})
|
|
}
|
|
}
|
|
}, async (request, reply) => {
|
|
const items = await feedGet(db, Context.create(request.userId), {
|
|
cursor: {
|
|
before: request.query?.before,
|
|
after: request.query?.after
|
|
},
|
|
limit: request.query?.limit
|
|
});
|
|
return reply.send({ items: items.items, hasMore: items.hasMore });
|
|
});
|
|
} |