MCPcopy Index your code
hub / github.com/CapSoftware/Cap / getTranscript

Function getTranscript

apps/web/actions/videos/get-transcript.ts:14–89  ·  view source on GitHub ↗
(
	videoId: Video.VideoId,
)

Source from the content-addressed store, hash-verified

12import { decodeStorageVideo } from "@/lib/video-storage";
13
14export async function getTranscript(
15 videoId: Video.VideoId,
16): Promise<{ success: boolean; content?: string; message: string }> {
17 const user = await getCurrentUser();
18
19 if (!videoId) {
20 return {
21 success: false,
22 message: "Missing required data for fetching transcript",
23 };
24 }
25
26 const exit = await Effect.gen(function* () {
27 const videosPolicy = yield* VideosPolicy;
28
29 return yield* Effect.promise(() =>
30 db().select({ video: videos }).from(videos).where(eq(videos.id, videoId)),
31 ).pipe(Policy.withPublicPolicy(videosPolicy.canView(videoId)));
32 }).pipe(provideOptionalAuth, EffectRuntime.runPromiseExit);
33
34 if (Exit.isFailure(exit)) {
35 return { success: false, message: "Video not found" };
36 }
37
38 const query = exit.value;
39
40 if (query.length === 0) {
41 return { success: false, message: "Video not found" };
42 }
43
44 const result = query[0];
45 if (!result?.video) {
46 return { success: false, message: "Video information is missing" };
47 }
48
49 const { video } = result;
50
51 if (video.transcriptionStatus !== "COMPLETE") {
52 return {
53 success: false,
54 message: "Transcript is not ready yet",
55 };
56 }
57
58 try {
59 const vttContent = await Effect.gen(function* () {
60 const [bucket] = yield* Storage.getAccessForVideo(
61 decodeStorageVideo(video),
62 );
63
64 return yield* bucket.getObject(
65 `${video.ownerId}/${videoId}/transcription.vtt`,
66 );
67 }).pipe(runPromise);
68
69 if (Option.isNone(vttContent)) {
70 return { success: false, message: "Transcript file not found" };
71 }

Callers 1

useTranscriptFunction · 0.90

Calls 3

dbFunction · 0.90
decodeStorageVideoFunction · 0.90
canViewMethod · 0.80

Tested by

no test coverage detected