The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as Cloudflare from "@alchemy.run/cloudflare"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import { HttpServerRequest } from "effect/http/HttpServerRequest"; |
| 4 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 5 | import * as Layer from "effect/Layer"; |
| 6 | import { DatabaseLive } from "./Db.ts"; |
| 7 | import { Files, FilesR2 } from "./Files.ts"; |
| 8 | import { History, HistoryLive } from "./History.ts"; |
| 9 | import Room from "./Room.ts"; |
| 10 | |
| 11 | // #region show |
| 12 | export default Cloudflare.Worker( |
| 13 | "Chat", |
| 14 | { main: import.meta.url }, |
| 15 | Effect.gen(function* () { |
| 16 | const rooms = yield* Room; |
| 17 | const history = yield* History; |
| 18 | const files = yield* Files; |
| 19 | |
| 20 | return { |
| 21 | fetch: Effect.gen(function* () { |
| 22 | const request = yield* HttpServerRequest; |
| 23 | const [, route, room, file] = request.url.split("/"); |
| 24 | if (route === "join") return yield* rooms.getByName(room!).fetch(request); |
| 25 | if (route === "upload") { |
| 26 | yield* files.upload(file!, yield* request.text); |
| 27 | return HttpServerResponse.empty({ status: 201 }); |
| 28 | } |
| 29 | return yield* HttpServerResponse.json(yield* history.list(room!)); |
| 30 | }) /*hide*/ |
| 31 | .pipe(Effect.orDie) /*end*/, |
| 32 | }; |
| 33 | }).pipe(Effect.provide([HistoryLive.pipe(Layer.provide(DatabaseLive)), FilesR2])), |
| 34 | ); |
| 35 | // #endregion show |