The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as Layer from "effect/Layer"; |
| 3 | import type { Bucket } from "./Bucket.ts"; |
| 4 | import { GrantOnBucket } from "./ObjectHttp.ts"; |
| 5 | import { makeObjectMedia } from "./ObjectMedia.ts"; |
| 6 | import { PutObject, type PutObjectRequest } from "./PutObject.ts"; |
| 7 | |
| 8 | /** |
| 9 | * HTTP implementation of {@link PutObject}. |
| 10 | * |
| 11 | * @layer |
| 12 | * @provides GCP.Storage.PutObject |
| 13 | */ |
| 14 | export const PutObjectHttp = Layer.effect( |
| 15 | PutObject, |
| 16 | Effect.gen(function* () { |
| 17 | const grantOnBucket = yield* GrantOnBucket; |
| 18 | const media = yield* makeObjectMedia; |
| 19 | return Effect.fn(function* (bucket: Bucket) { |
| 20 | yield* grantOnBucket("GCP.Storage.PutObject", bucket, "roles/storage.objectUser"); |
| 21 | const bucketName = yield* bucket.bucketName; |
| 22 | return Effect.fn(`GCP.Storage.PutObject(${bucket.LogicalId})`)(function* ( |
| 23 | request: PutObjectRequest, |
| 24 | ) { |
| 25 | const name = yield* bucketName; |
| 26 | return yield* media.upload(name, request); |
| 27 | }); |
| 28 | }); |
| 29 | }), |
| 30 | ); |