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

main
ts 47 lines 1.78 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 PresignGetOnlyTestFunction extends Lambda.Function<PresignGetOnlyTestFunction>()(
8 "PresignGetOnlyTestFunction",
9 ) {}
10
11 export default PresignGetOnlyTestFunction.make(
12 { main: import.meta.url, functionUrl: true },
13 Effect.gen(function* () {
14 const bucket = yield* S3.Bucket("PresignGetOnlyBucket", {
15 forceDestroy: true,
16 versioning: "Enabled",
17 });
18 const presignGet = yield* S3.PresignGetObject(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* HttpServerResponse.json({
35 url: yield* presignGet({
36 key,
37 versionId: url.searchParams.get("versionId") ?? undefined,
38 contentType: url.searchParams.get("contentType") ?? undefined,
39 expiresIn: url.searchParams.has("expiresIn")
40 ? Number(url.searchParams.get("expiresIn"))
41 : undefined,
42 }),
43 });
44 }).pipe(Effect.orDie),
45 };
46 }).pipe(Effect.provide(S3.PresignGetObjectHttp)),
47 );