Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix: remove partial copies when a Loom import move fails
Richie McIlroy5178d975a39b
diff --git a/apps/web/__tests__/unit/loom-operator-tools.test.ts b/apps/web/__tests__/unit/loom-operator-tools.test.tsindex 00073dc76..bb61e5314 100644--- a/apps/web/__tests__/unit/loom-operator-tools.test.ts+++ b/apps/web/__tests__/unit/loom-operator-tools.test.ts@@ -358,7 +358,12 @@ describe("reassignLoomImport", () => {mocks.headSize = 1;await expect(reassignLoomImport(input)).rejects.toThrow("size mismatch");expect(mocks.updates).toEqual([]);- expect(mocks.removed).toEqual([]);+ expect(mocks.removed).toEqual([+ [+ `${ids.to}/${ids.video}/result.mp4`,+ `${ids.to}/${ids.video}/screenshot/screen-capture.jpg`,+ ],+ ]);});it("keeps the original files when the owner changed during the move", async () => {diff --git a/apps/web/lib/loom-import-reassign.ts b/apps/web/lib/loom-import-reassign.tsindex 6fc4d80dc..9cc65c4d3 100644--- a/apps/web/lib/loom-import-reassign.ts+++ b/apps/web/lib/loom-import-reassign.ts@@ -151,30 +151,34 @@ export async function reassignLoomImport({};const transcriptKey = getEditTranscriptObjectKey(fromUserId, videoId);- let copiedObjects = 0;- for (let index = 0; index < source.objects.length; index += 4) {- await Promise.all(- source.objects.slice(index, index + 4).map(async (object) => {- const destinationKey = object.key.replace(- source.prefix,- destination.prefix,- );- if (object.key === transcriptKey) {- const stored = Option.getOrNull(- await runPromise(source.bucket.getObject(object.key)),- );- const transcript =- stored && decryptEditTranscriptObject(stored, fromUserId, videoId);- if (!transcript)- throw new Error(`Could not read the transcript for ${videoId}`);- await runPromise(- source.bucket.putObject(- destinationKey,- encryptEditTranscriptObject(transcript, toUserId, videoId),- { contentType: "application/octet-stream" },- ),+ const written: string[] = [];+ try {+ for (let index = 0; index < source.objects.length; index += 4) {+ await Promise.all(+ source.objects.slice(index, index + 4).map(async (object) => {+ const destinationKey = object.key.replace(+ source.prefix,+ destination.prefix,);- } else {+ written.push(destinationKey);+ if (object.key === transcriptKey) {+ const stored = Option.getOrNull(+ await runPromise(source.bucket.getObject(object.key)),+ );+ const transcript =+ stored &&+ decryptEditTranscriptObject(stored, fromUserId, videoId);+ if (!transcript)+ throw new Error(`Could not read the transcript for ${videoId}`);+ await runPromise(+ source.bucket.putObject(+ destinationKey,+ encryptEditTranscriptObject(transcript, toUserId, videoId),+ { contentType: "application/octet-stream" },+ ),+ );+ return;+ }await runPromise(source.bucket.copyObjectForRecording(`${source.bucket.bucketName}/${object.key}`,@@ -186,11 +190,16 @@ export async function reassignLoomImport({);if (head.ContentLength !== object.size)throw new Error(`Copied object size mismatch for ${object.key}`);- }- copiedObjects++;- }),- );+ }),+ );+ }+ } catch (error) {+ await runPromise(+ source.bucket.deleteObjects(written.map((key) => ({ Key: key }))),+ ).catch(() => undefined);+ throw error;}+ const copiedObjects = written.length;const updated = await db().transaction(async (tx) => {const result = await tx