@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 47 lines 1.5 KB
Raw
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 { Email } from "./sender.ts";
6
7 export default class SendEmailWorker extends Cloudflare.Worker<SendEmailWorker>()(
8 "SendEmailTestWorker",
9 {
10 main: import.meta.url,
11 },
12 Effect.gen(function* () {
13 const email = yield* Cloudflare.Email.Send(Email);
14
15 return {
16 fetch: Effect.gen(function* () {
17 const request = yield* HttpServerRequest;
18 const url = new URL(request.url, "http://x");
19
20 if (url.pathname === "/send") {
21 const from = url.searchParams.get("from")!;
22 const to = url.searchParams.get("to")!;
23 const subject = url.searchParams.get("subject") ?? "alchemy test";
24 const result = yield* email
25 .send({
26 from,
27 to,
28 subject,
29 text: `sent at ${new Date().toISOString()}`,
30 })
31 .pipe(
32 Effect.match({
33 onSuccess: () => ({ ok: true as const }),
34 onFailure: (err) => ({
35 ok: false as const,
36 message: err.message,
37 }),
38 }),
39 );
40 return yield* HttpServerResponse.json(result);
41 }
42
43 return HttpServerResponse.text("ok");
44 }),
45 };
46 }).pipe(Effect.provide(Cloudflare.Email.SendBinding)),
47 ) {}