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
| 1 | import { R2 } from "@alchemy.run/cloudflare"; |
| 2 | import type * as Alchemy from "alchemy"; |
| 3 | import * as Context from "effect/Context"; |
| 4 | import * as Data from "effect/Data"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Layer from "effect/Layer"; |
| 7 | |
| 8 | // #region show |
| 9 | // #region service |
| 10 | export class UploadError extends Data.TaggedError("UploadError")<{ cause: unknown }> {} |
| 11 | |
| 12 | export class Files extends Context.Service< |
| 13 | Files, |
| 14 | { |
| 15 | upload(name: string, body: string): Effect.Effect<void, UploadError, Alchemy.RuntimeContext>; |
| 16 | } |
| 17 | >()("Files") {} |
| 18 | // #endregion service |
| 19 | // #region live |
| 20 | |
| 21 | export const FilesR2 = Layer.effect( |
| 22 | Files, |
| 23 | Effect.gen(function* () { |
| 24 | // #region construct |
| 25 | // #region bucket |
| 26 | const bucket = yield* R2.Bucket("Files"); |
| 27 | // #endregion bucket |
| 28 | // #region binding |
| 29 | const files = yield* R2.ReadWriteBucket(bucket); |
| 30 | // #endregion binding |
| 31 | // #endregion construct |
| 32 | // #region methods |
| 33 | |
| 34 | return { |
| 35 | upload: (name: string, body: string) => |
| 36 | files |
| 37 | .put(name, body) /*hide*/ |
| 38 | .pipe( |
| 39 | Effect.asVoid, |
| 40 | Effect.mapError((cause) => new UploadError({ cause })), |
| 41 | ) /*end*/, |
| 42 | }; |
| 43 | // #endregion methods |
| 44 | }), |
| 45 | ) /*hide*/ |
| 46 | .pipe(Layer.provide(R2.ReadWriteBucketBinding)); /*end*/ |
| 47 | // #endregion live |
| 48 | // #endregion show |