Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(web): guard edit upload cleanup
Richie McIlroy3f3ec3028d34
diff --git a/apps/web/__tests__/unit/save-video-edits.test.ts b/apps/web/__tests__/unit/save-video-edits.test.tsindex e31d4e39c..88fe78a7d 100644--- a/apps/web/__tests__/unit/save-video-edits.test.ts+++ b/apps/web/__tests__/unit/save-video-edits.test.ts@@ -91,6 +91,33 @@ describe("saveVideoEdits", () => {expect(insertMock).not.toHaveBeenCalled();});+ it("rejects completed edit rows before the workflow clears them", async () => {+ getCurrentUserMock.mockResolvedValueOnce({ id: "user-1", isPro: true });+ whereMock+ .mockResolvedValueOnce([+ {+ id: "video-1",+ ownerId: "user-1",+ duration: 10,+ source: { type: "webMP4" },+ isScreenshot: false,+ metadata: null,+ },+ ])+ .mockResolvedValueOnce([{ phase: "complete" }]);+ const { saveVideoEdits } = await import("@/actions/videos/save-edits");++ await expect(+ saveVideoEdits("video-1" as never, {+ version: 1,+ sourceDuration: 10,+ keepRanges: [{ start: 0, end: 10 }],+ }),+ ).rejects.toThrow("Video is already uploading or processing");++ expect(insertMock).not.toHaveBeenCalled();+ });+it("requires Cap Pro before saving edits", async () => {getCurrentUserMock.mockResolvedValueOnce({ id: "user-1", isPro: false });const { saveVideoEdits } = await import("@/actions/videos/save-edits");diff --git a/apps/web/actions/videos/save-edits.ts b/apps/web/actions/videos/save-edits.tsindex 4ec30ca52..64c5cbdf2 100644--- a/apps/web/actions/videos/save-edits.ts+++ b/apps/web/actions/videos/save-edits.ts@@ -27,6 +27,7 @@ const ACTIVE_UPLOAD_PHASES = new Set(["uploading","processing","generating_thumbnail",+ "complete",]);function isMp4BackedVideo(source: typeof videos.$inferSelect.source) {diff --git a/apps/web/workflows/edit-video.ts b/apps/web/workflows/edit-video.tsindex 57e614de5..8af887d75 100644--- a/apps/web/workflows/edit-video.ts+++ b/apps/web/workflows/edit-video.ts@@ -13,7 +13,7 @@ import type {import { serverEnv } from "@cap/env";import { Storage } from "@cap/web-backend";import { Video } from "@cap/web-domain";-import { eq } from "drizzle-orm";+import { and, eq } from "drizzle-orm";import { FatalError } from "workflow";import { runPromise } from "@/lib/server";import { remapCurrentOutputTimeThroughEdit } from "@/lib/video-edits";@@ -481,7 +481,13 @@ async function saveEditResultAndComplete(await tx.delete(videoUploads)- .where(eq(videoUploads.videoId, videoId as Video.VideoId));+ .where(+ and(+ eq(videoUploads.videoId, videoId as Video.VideoId),+ eq(videoUploads.phase, "complete"),+ eq(videoUploads.rawFileKey, sourceKey),+ ),+ );});try {