@devries-cameron20 / t3code Mirror · read-only
Fork 0

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, 04:45 UTC

main
ts 50 lines 1.82 KB
Raw
1 import * as transcoder from "@distilled.cloud/gcp/transcoder_v1";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as GCPBindings from "../GCPBindings.ts";
5 import { CreateJob, type CreateJobRequest } from "./CreateJob.ts";
6 import { lastSegment, parentOfName } from "./internal.ts";
7 import type { JobTemplate } from "./JobTemplate.ts";
8
9 /**
10 * HTTP implementation of {@link CreateJob}.
11 *
12 * @layer
13 * @provides GCP.Transcoder.CreateJob
14 */
15 export const CreateJobHttp = Layer.effect(
16 CreateJob,
17 Effect.gen(function* () {
18 const bind = yield* GCPBindings.Bind;
19 const createProjectsLocationsJobs = yield* GCPBindings.withCredentials(
20 transcoder.createProjectsLocationsJobs,
21 );
22 return Effect.fn(function* (template: JobTemplate) {
23 if (!globalThis.__ALCHEMY_RUNTIME__) {
24 yield* bind`GCP.Transcoder.CreateJob(${template})`({
25 // Narrowest predefined role with transcoder.jobs.create; Transcoder
26 // has no resource-level IAM, so this is a project grant.
27 iam: [{ role: "roles/transcoder.editor" }],
28 });
29 }
30 const name = yield* template.name;
31 const location = yield* template.location;
32 return Effect.fn(`GCP.Transcoder.CreateJob(${template.LogicalId})`)(function* (
33 request?: CreateJobRequest,
34 ) {
35 const templateName = yield* name;
36 const templateLocation = yield* location;
37 const templateId = lastSegment(templateName);
38 const config = request?.body?.config;
39 return yield* createProjectsLocationsJobs({
40 parent: parentOfName(templateName, templateLocation),
41 body: {
42 ...request?.body,
43 templateId:
44 request?.body?.templateId ?? (config === undefined ? templateId : undefined),
45 },
46 });
47 });
48 });
49 }),
50 );