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 | |
| 4 | /** |
| 5 | * One instance per short link. It keeps the link's click count in |
| 6 | * transactional storage and pushes every change to the dashboards watching |
| 7 | * it. The WebSockets are hibernatable: the object can be evicted while they |
| 8 | * stay open. |
| 9 | */ |
| 10 | export default class LinkRoom extends Cloudflare.DurableObject<LinkRoom>()( |
| 11 | "LinkRoom", |
| 12 | Effect.gen(function* () { |
| 13 | const state = yield* Cloudflare.DurableObjectState; |
| 14 | |
| 15 | return Effect.gen(function* () { |
| 16 | let clicks = (yield* state.storage.get<number>("clicks")) ?? 0; |
| 17 | |
| 18 | return { |
| 19 | record: Effect.fn(function* (n: number) { |
| 20 | clicks += n; |
| 21 | yield* state.storage.put("clicks", clicks); |
| 22 | for (const socket of yield* state.getWebSockets()) { |
| 23 | yield* socket.send(JSON.stringify({ clicks })); |
| 24 | } |
| 25 | return clicks; |
| 26 | }), |
| 27 | fetch: Effect.gen(function* () { |
| 28 | const [response, socket] = yield* Cloudflare.upgrade(); |
| 29 | yield* socket.send(JSON.stringify({ clicks })); |
| 30 | return response; |
| 31 | }), |
| 32 | }; |
| 33 | }); |
| 34 | }), |
| 35 | ) {} |