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

main
ts 47 lines 1.7 KB
Raw
1 import type * as Credentials from "@distilled.cloud/aws/Credentials";
2 import * as Presign from "@distilled.cloud/aws/Presign";
3 import type * as Region from "@distilled.cloud/aws/Region";
4 import * as Output from "alchemy/Output";
5 import * as Effect from "effect/Effect";
6 import * as Layer from "effect/Layer";
7 import * as AWSBindings from "../AWSBindings.ts";
8 import type { Bucket } from "./Bucket.ts";
9 import { PresignGetObject, type PresignGetObjectRequest } from "./PresignGetObject.ts";
10
11 export const PresignGetObjectHttp = Layer.effect(
12 PresignGetObject,
13 Effect.gen(function* () {
14 const bind = yield* AWSBindings.Bind;
15 const services = yield* AWSBindings.withCredentials(
16 Effect.context<Credentials.Credentials | Region.Region>(),
17 );
18
19 return Effect.fn(function* (bucket: Bucket) {
20 const BucketName = yield* bucket.bucketName;
21 if (!globalThis.__ALCHEMY_RUNTIME__) {
22 yield* bind`AWS.S3.PresignGetObject(${bucket})`({
23 policyStatements: [
24 {
25 Effect: "Allow",
26 Action: ["s3:GetObject", "s3:GetObjectVersion"],
27 Resource: [Output.interpolate`${bucket.bucketArn}/*`],
28 },
29 ],
30 });
31 }
32 return Effect.fn(`AWS.S3.PresignGetObject(${bucket.LogicalId})`)(function* (
33 request: PresignGetObjectRequest,
34 ) {
35 const bucketName = yield* BucketName;
36 return yield* Presign.presignS3Url({
37 method: "GET",
38 bucket: bucketName,
39 key: request.key,
40 versionId: request.versionId,
41 expiresIn: request.expiresIn,
42 responseContentType: request.contentType,
43 }).pipe(Effect.provideContext(services));
44 });
45 });
46 }),
47 );