( videoId: Video.VideoId, targetLanguage: LanguageCode, )
| 23 | } |
| 24 | |
| 25 | export async function translateTranscript( |
| 26 | videoId: Video.VideoId, |
| 27 | targetLanguage: LanguageCode, |
| 28 | ): Promise<TranslateResult> { |
| 29 | if (!videoId || !targetLanguage) { |
| 30 | return { |
| 31 | success: false, |
| 32 | message: "Missing required parameters", |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | if (!SUPPORTED_LANGUAGES[targetLanguage]) { |
| 37 | return { |
| 38 | success: false, |
| 39 | message: "Unsupported language", |
| 40 | }; |
| 41 | } |
| 42 | |
| 43 | const groq = getGroqClient(); |
| 44 | if (!groq) { |
| 45 | return { |
| 46 | success: false, |
| 47 | message: "Translation service not configured", |
| 48 | }; |
| 49 | } |
| 50 | |
| 51 | if (await isRateLimited(RATE_LIMIT_IDS.TRANSLATE_TRANSCRIPT)) { |
| 52 | return { success: false, message: "Too many requests" }; |
| 53 | } |
| 54 | |
| 55 | const exit = await Effect.gen(function* () { |
| 56 | const videosPolicy = yield* VideosPolicy; |
| 57 | |
| 58 | return yield* Effect.promise(() => |
| 59 | db().select({ video: videos }).from(videos).where(eq(videos.id, videoId)), |
| 60 | ).pipe(Policy.withPublicPolicy(videosPolicy.canView(videoId))); |
| 61 | }).pipe(provideOptionalAuth, EffectRuntime.runPromiseExit); |
| 62 | |
| 63 | if (Exit.isFailure(exit)) { |
| 64 | return { success: false, message: "Video not found" }; |
| 65 | } |
| 66 | |
| 67 | const query = exit.value; |
| 68 | |
| 69 | if (query.length === 0 || !query[0]?.video) { |
| 70 | return { success: false, message: "Video not found" }; |
| 71 | } |
| 72 | |
| 73 | const { video } = query[0]; |
| 74 | |
| 75 | const translatedKey = `${video.ownerId}/${videoId}/transcription.${targetLanguage}.vtt`; |
| 76 | |
| 77 | try { |
| 78 | const existingTranslation = await Effect.gen(function* () { |
| 79 | const [bucket] = yield* Storage.getAccessForVideo( |
| 80 | decodeStorageVideo(video), |
| 81 | ); |
| 82 | return yield* bucket.getObject(translatedKey); |
no test coverage detected