Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Only store valid video duration

Richie McIlroy5212e3e8f048
diff --git a/apps/web/app/api/webhooks/media-server/progress/route.ts b/apps/web/app/api/webhooks/media-server/progress/route.ts
index 5fac75e2c..b82ef64f1 100644
--- a/apps/web/app/api/webhooks/media-server/progress/route.ts
+++ b/apps/web/app/api/webhooks/media-server/progress/route.ts
@@ -35,6 +35,10 @@ interface ProgressWebhookPayload {
};
}
+function getValidDuration(duration: number) {
+ return Number.isFinite(duration) && duration > 0 ? duration : undefined;
+}
+
function mapPhaseToDbPhase(
phase: ProgressWebhookPayload["phase"],
): "uploading" | "processing" | "generating_thumbnail" | "complete" | "error" {
@@ -77,12 +81,14 @@ export async function POST(request: NextRequest) {
if (dbPhase === "complete") {
if (payload.metadata) {
+ const duration = getValidDuration(payload.metadata.duration);
+
await db()
.update(videos)
.set({
width: payload.metadata.width,
height: payload.metadata.height,
- duration: payload.metadata.duration,
+ ...(duration === undefined ? {} : { duration }),
})
.where(eq(videos.id, payload.videoId as Video.VideoId));
}
diff --git a/apps/web/workflows/process-video.ts b/apps/web/workflows/process-video.ts
index f2113350c..943ff7fa9 100644
--- a/apps/web/workflows/process-video.ts
+++ b/apps/web/workflows/process-video.ts
@@ -26,6 +26,10 @@ interface VideoProcessingResult {
};
}
+function getValidDuration(duration: number) {
+ return Number.isFinite(duration) && duration > 0 ? duration : undefined;
+}
+
export async function processVideoWorkflow(
payload: ProcessVideoWorkflowPayload,
): Promise<VideoProcessingResult> {
@@ -246,13 +250,15 @@ async function saveMetadataAndComplete(
): Promise<void> {
"use step";
+ const duration = getValidDuration(metadata.duration);
+
await db()
.update(videos)
.set({
width: metadata.width,
height: metadata.height,
- duration: metadata.duration,
fps: metadata.fps,
+ ...(duration === undefined ? {} : { duration }),
})
.where(eq(videos.id, videoId as Video.VideoId));