A Cloudflare Worker which works in conjunction with https://github.com/indexxing/bsky-alt-text
1import { Bool, Num, OpenAPIRoute } from "chanfana";
2import { z } from "zod";
3import { type AppContext, Task } from "../types";
4
5export class TaskList extends OpenAPIRoute {
6 schema = {
7 tags: ["Tasks"],
8 summary: "List Tasks",
9 request: {
10 query: z.object({
11 page: Num({
12 description: "Page number",
13 default: 0,
14 }),
15 isCompleted: Bool({
16 description: "Filter by completed flag",
17 required: false,
18 }),
19 }),
20 },
21 responses: {
22 "200": {
23 description: "Returns a list of tasks",
24 content: {
25 "application/json": {
26 schema: z.object({
27 series: z.object({
28 success: Bool(),
29 result: z.object({
30 tasks: Task.array(),
31 }),
32 }),
33 }),
34 },
35 },
36 },
37 },
38 };
39
40 async handle(c: AppContext) {
41 // Get validated data
42 const data = await this.getValidatedData<typeof this.schema>();
43
44 // Retrieve the validated parameters
45 const { page, isCompleted } = data.query;
46
47 // Implement your own object list here
48
49 return {
50 success: true,
51 tasks: [
52 {
53 name: "Clean my room",
54 slug: "clean-room",
55 description: null,
56 completed: false,
57 due_date: "2025-01-05",
58 },
59 {
60 name: "Build something awesome with Cloudflare Workers",
61 slug: "cloudflare-workers",
62 description: "Lorem Ipsum",
63 completed: true,
64 due_date: "2022-12-24",
65 },
66 ],
67 };
68 }
69}