Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: remove copied files when a Loom import move loses its claim

Richie McIlroyd33e8abd0ac4
diff --git a/apps/web/__tests__/unit/loom-operator-tools.test.ts b/apps/web/__tests__/unit/loom-operator-tools.test.ts
index a2df47179..32ea6b57c 100644
--- a/apps/web/__tests__/unit/loom-operator-tools.test.ts
+++ b/apps/web/__tests__/unit/loom-operator-tools.test.ts
@@ -397,13 +397,18 @@ describe("reassignLoomImport", () => {
]);
});
- it("keeps the original files when the owner changed during the move", async () => {
+ it("keeps the original files and removes its copies when the claim was lost", async () => {
mocks.selects = [[importedVideo()], [{ userId: ids.to }]];
mocks.affectedRows = 0;
await expect(reassignLoomImport(input)).resolves.toMatchObject({
status: "failed",
});
- expect(mocks.removed).toEqual([]);
+ expect(mocks.removed).toEqual([
+ [
+ `${ids.to}/${ids.video}/result.mp4`,
+ `${ids.to}/${ids.video}/screenshot/screen-capture.jpg`,
+ ],
+ ]);
});
});
diff --git a/apps/web/lib/loom-import-reassign.ts b/apps/web/lib/loom-import-reassign.ts
index 66365f47b..270fdc733 100644
--- a/apps/web/lib/loom-import-reassign.ts
+++ b/apps/web/lib/loom-import-reassign.ts
@@ -279,8 +279,12 @@ async function moveClaimedVideo({
await tx.delete(spaceVideos).where(eq(spaceVideos.videoId, id));
return true;
});
- if (!updated)
- return { videoId, status: "failed", reason: "owner changed during move" };
+ if (!updated) {
+ await runPromise(
+ source.bucket.deleteObjects(written.map((key) => ({ Key: key }))),
+ ).catch(() => undefined);
+ return { videoId, status: "failed", reason: "move claim was lost" };
+ }
try {
await runPromise(