MCPcopy
hub / github.com/CapSoftware/Cap / getVideoStatus

Function getVideoStatus

apps/web/actions/videos/get-status.ts:44–213  ·  view source on GitHub ↗
(
	videoId: Video.VideoId,
)

Source from the content-addressed store, hash-verified

42}
43
44export async function getVideoStatus(
45 videoId: Video.VideoId,
46): Promise<VideoStatusResult | { success: false }> {
47 if (!videoId) throw new Error("Video ID not provided");
48
49 const exit = await Effect.gen(function* () {
50 const videosPolicy = yield* VideosPolicy;
51
52 return yield* Effect.promise(() =>
53 db().select().from(videos).where(eq(videos.id, videoId)),
54 ).pipe(Policy.withPublicPolicy(videosPolicy.canView(videoId)));
55 }).pipe(provideOptionalAuth, EffectRuntime.runPromiseExit);
56
57 if (Exit.isFailure(exit)) return { success: false };
58
59 const video = exit.value[0];
60 if (!video) throw new Error("Video not found");
61
62 const metadata: VideoMetadata = (video.metadata as VideoMetadata) || {};
63
64 if (!video.transcriptionStatus && serverEnv().DEEPGRAM_API_KEY) {
65 const activeUpload = await db()
66 .select({
67 videoId: videoUploads.videoId,
68 phase: videoUploads.phase,
69 processingError: videoUploads.processingError,
70 })
71 .from(videoUploads)
72 .where(eq(videoUploads.videoId, videoId))
73 .limit(1);
74
75 if (activeUpload.length > 0) {
76 const upload = activeUpload[0];
77 if (
78 video.source?.type === "desktopSegments" &&
79 upload?.phase === "error" &&
80 isRetryableDesktopSegmentsFinalizationError(upload.processingError)
81 ) {
82 queueDesktopSegmentsFinalization({
83 videoId,
84 userId: video.ownerId,
85 }).catch((error) => {
86 console.error(
87 `[Get Status] Error queueing segment finalization for video ${videoId}:`,
88 error,
89 );
90 });
91 }
92
93 return {
94 transcriptionStatus: null,
95 aiGenerationStatus:
96 (metadata.aiGenerationStatus as AiGenerationStatus) || null,
97 name: video.name,
98 aiTitle: metadata.aiTitle || null,
99 summary: metadata.summary || null,
100 chapters: metadata.chapters || null,
101 };

Callers 1

useVideoStatusFunction · 0.90

Calls 8

dbFunction · 0.90
serverEnvFunction · 0.90
transcribeVideoFunction · 0.90
isAiGenerationEnabledFunction · 0.90
startAiGenerationFunction · 0.90
canViewMethod · 0.80

Tested by

no test coverage detected