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

main
ts 52 lines 1.86 KB
Raw
1 import * as Lambda from "@alchemy.run/aws/Lambda";
2 import * as S3 from "@alchemy.run/aws/S3";
3 import * as Effect from "effect/Effect";
4 import { HttpServerRequest } from "effect/http/HttpServerRequest";
5 import * as HttpServerResponse from "effect/http/HttpServerResponse";
6
7 export class HeadObjectTestFunction extends Lambda.Function<HeadObjectTestFunction>()(
8 "HeadObjectTestFunction",
9 ) {}
10
11 export default HeadObjectTestFunction.make(
12 { main: import.meta.url, functionUrl: true },
13 Effect.gen(function* () {
14 const bucket = yield* S3.Bucket("HeadObjectBucket", {
15 forceDestroy: true,
16 versioning: "Enabled",
17 });
18 const headObject = yield* S3.HeadObject(bucket);
19 const bucketName = yield* bucket.bucketName;
20 const bucketArn = yield* bucket.bucketArn;
21
22 return {
23 fetch: Effect.gen(function* () {
24 const request = yield* HttpServerRequest;
25 const url = yield* Effect.sync(() => new URL(request.originalUrl));
26 if (url.pathname === "/info") {
27 return yield* HttpServerResponse.json({
28 bucketName: yield* bucketName,
29 bucketArn: yield* bucketArn,
30 });
31 }
32 const key = url.searchParams.get("key");
33 if (!key) return HttpServerResponse.text("Missing key", { status: 400 });
34 return yield* headObject({
35 Key: key,
36 VersionId: url.searchParams.get("versionId") ?? undefined,
37 }).pipe(
38 Effect.flatMap((result) =>
39 HttpServerResponse.json({
40 contentLength: result.ContentLength,
41 contentType: result.ContentType,
42 versionId: result.VersionId,
43 }),
44 ),
45 Effect.catchTag("NotFound", () =>
46 HttpServerResponse.json({ tag: "NotFound" }, { status: 404 }),
47 ),
48 );
49 }).pipe(Effect.orDie),
50 };
51 }).pipe(Effect.provide(S3.HeadObjectHttp)),
52 );