Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(web): queue transcription after video processing
Richie McIlroy42ac15d14352
diff --git a/apps/web/workflows/process-video.ts b/apps/web/workflows/process-video.tsindex ada943223..e96b17ee7 100644--- a/apps/web/workflows/process-video.ts+++ b/apps/web/workflows/process-video.ts@@ -1,12 +1,14 @@import { db } from "@cap/database";-import { videos, videoUploads } from "@cap/database/schema";+import { users, videos, videoUploads } from "@cap/database/schema";import { serverEnv } from "@cap/env";-import { Storage } from "@cap/web-backend";+import { Storage } from "@cap/web-backend/src/Storage/index";import { Video } from "@cap/web-domain";import { eq } from "drizzle-orm";import { FatalError } from "workflow";-import { runPromise } from "@/lib/server";+import { isAiGenerationEnabledForUser } from "@/lib/ai-generation-entitlement";+import { transcribeVideo } from "@/lib/transcribe";import { decodeStorageVideo } from "@/lib/video-storage";+import { runWorkflowPromise } from "@/lib/workflow-runtime";interface ProcessVideoWorkflowPayload {videoId: string;@@ -54,6 +56,8 @@ export async function processVideoWorkflow(await cleanupRawUpload(videoId, rawFileKey);}+ await queueProcessedVideoTranscription(videoId);+return {success: true,message: "Video processing completed",@@ -248,13 +252,13 @@ async function processVideoOnMediaServer(const videoDomain = decodeStorageVideo(video);const [bucket] =- await Storage.getAccessForVideo(videoDomain).pipe(runPromise);+ await Storage.getAccessForVideo(videoDomain).pipe(runWorkflowPromise);const rawVideoUrl = await bucket.getInternalSignedObjectUrl(rawFileKey, {expiresIn: MEDIA_SERVER_PRESIGNED_GET_EXPIRES_SECONDS,})- .pipe(runPromise);+ .pipe(runWorkflowPromise);const outputKey = `${userId}/${videoId}/result.mp4`;const thumbnailKey = `${userId}/${videoId}/screenshot/screen-capture.jpg`;@@ -268,7 +272,7 @@ async function processVideoOnMediaServer(},{ expiresIn: MEDIA_SERVER_PRESIGNED_PUT_EXPIRES_SECONDS },)- .pipe(runPromise);+ .pipe(runWorkflowPromise);const thumbnailPresignedUrl = await bucket.getInternalPresignedPutUrl(@@ -278,7 +282,7 @@ async function processVideoOnMediaServer(},{ expiresIn: MEDIA_SERVER_PRESIGNED_PUT_EXPIRES_SECONDS },)- .pipe(runPromise);+ .pipe(runWorkflowPromise);const previewGifPresignedUrl = await bucket.getInternalPresignedPutUrl(@@ -289,7 +293,7 @@ async function processVideoOnMediaServer(},{ expiresIn: MEDIA_SERVER_PRESIGNED_PUT_EXPIRES_SECONDS },)- .pipe(runPromise);+ .pipe(runWorkflowPromise);const webhookUrl = `${webhookBaseUrl}/api/webhooks/media-server/progress?retryable=true`;const webhookSecret = serverEnv().MEDIA_SERVER_WEBHOOK_SECRET;@@ -456,14 +460,52 @@ async function cleanupRawUpload(const videoDomain = decodeStorageVideo(video);const [bucket] =- await Storage.getAccessForVideo(videoDomain).pipe(runPromise);+ await Storage.getAccessForVideo(videoDomain).pipe(runWorkflowPromise);- await bucket.deleteObject(rawFileKey).pipe(runPromise);+ await bucket.deleteObject(rawFileKey).pipe(runWorkflowPromise);} catch (error) {console.error("[process-video] Failed to delete raw upload", error);}}+async function queueProcessedVideoTranscription(+ videoId: string,+): Promise<void> {+ "use step";++ try {+ const [owner] = await db()+ .select({+ id: videos.ownerId,+ stripeSubscriptionStatus: users.stripeSubscriptionStatus,+ thirdPartyStripeSubscriptionId: users.thirdPartyStripeSubscriptionId,+ })+ .from(videos)+ .innerJoin(users, eq(videos.ownerId, users.id))+ .where(eq(videos.id, Video.VideoId.make(videoId)));++ if (!owner) return;++ const result = await transcribeVideo(+ Video.VideoId.make(videoId),+ owner.id,+ isAiGenerationEnabledForUser(owner),+ );++ if (!result.success) {+ console.warn("[process-video] Failed to queue transcription", {+ videoId,+ message: result.message,+ });+ }+ } catch (error) {+ console.warn("[process-video] Failed to queue transcription", {+ videoId,+ error,+ });+ }+}+async function setProcessingError(videoId: string,errorMessage: string,