( videoId: Video.VideoId, )
| 12 | import { decodeStorageVideo } from "@/lib/video-storage"; |
| 13 | |
| 14 | export 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 | } |
no test coverage detected