The best way to control Claude Code, Codex and more from any computer or phone

main
ts 45 lines 1.37 KB
Raw
1 import * as HttpApi from "effect/http-api/HttpApi";
2 import * as HttpApiEndpoint from "effect/http-api/HttpApiEndpoint";
3 import * as HttpApiGroup from "effect/http-api/HttpApiGroup";
4 import * as Schema from "effect/Schema";
5 import { LinkNotFound } from "./Links.ts";
6
7 export const LinkView = Schema.Struct({
8 code: Schema.String,
9 url: Schema.String,
10 createdAt: Schema.Number,
11 preview: Schema.optional(Schema.Struct({ title: Schema.String, fetchedAt: Schema.Number })),
12 clicks: Schema.Number,
13 });
14 export type LinkView = typeof LinkView.Type;
15
16 const Code = Schema.Struct({ code: Schema.String });
17
18 export class LinksGroup extends HttpApiGroup.make("links")
19 .add(
20 HttpApiEndpoint.post("create", "/links", {
21 payload: Schema.Struct({ url: Schema.String }),
22 success: LinkView,
23 }),
24 )
25 .add(
26 HttpApiEndpoint.post("import", "/links/import", {
27 payload: Schema.Struct({ urls: Schema.Array(Schema.String) }),
28 success: Schema.Array(LinkView),
29 }),
30 )
31 .add(
32 HttpApiEndpoint.get("list", "/links", {
33 success: Schema.Array(LinkView),
34 }),
35 )
36 .add(
37 HttpApiEndpoint.get("get", "/links/:code", {
38 params: Code,
39 success: LinkView,
40 error: LinkNotFound,
41 }),
42 ) {}
43
44 /** The public API: imported by the Worker to serve it and by the dashboard to call it. */
45 export class ShortyApi extends HttpApi.make("ShortyApi").add(LinksGroup) {}