Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Treat server-side processing as non-fatal on upload

Richie McIlroy07ffeccc4233
diff --git a/apps/web/__tests__/unit/instant-recording-uploader.test.ts b/apps/web/__tests__/unit/instant-recording-uploader.test.ts
index 69eb92ba0..dc1eaf0d8 100644
--- a/apps/web/__tests__/unit/instant-recording-uploader.test.ts
+++ b/apps/web/__tests__/unit/instant-recording-uploader.test.ts
@@ -450,7 +450,7 @@ describe("InstantRecordingUploader", () => {
);
});
- it("fails finalize when server-side processing cannot start", async () => {
+ it("keeps finalize successful when server-side processing has not started yet", async () => {
const fetchMock = vi.fn(
async (input: RequestInfo | URL, init?: RequestInit) => {
const url = input.toString();
@@ -499,7 +499,8 @@ describe("InstantRecordingUploader", () => {
durationSeconds: 12,
subpath: "raw-upload.webm",
}),
- ).rejects.toThrow("Video uploaded, but processing could not start");
+ ).resolves.toBeUndefined();
+ expect(uploader.getProcessingStarted()).toBe(false);
});
it("treats interrupted multipart completion as uncertain instead of fatal cleanup", async () => {
diff --git a/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/instant-mp4-uploader.ts b/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/instant-mp4-uploader.ts
index b9c356792..b9c931c6c 100644
--- a/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/instant-mp4-uploader.ts
+++ b/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/instant-mp4-uploader.ts
@@ -134,7 +134,7 @@ const completeMultipartUpload = async (
uploadId: string,
parts: UploadedPartPayload[],
meta: MultipartCompletePayload,
-) => {
+): Promise<{ processingStarted: boolean }> => {
try {
const response = await postJson<{
success: boolean;
@@ -150,14 +150,10 @@ const completeMultipartUpload = async (
fps: meta.fps,
});
- if (response.processingStarted === false) {
- throw new ProcessingStartError();
- }
+ return {
+ processingStarted: response.processingStarted !== false,
+ };
} catch (error) {
- if (error instanceof ProcessingStartError) {
- throw error;
- }
-
if (error instanceof HttpRequestError && error.status < 500) {
throw error;
}
@@ -214,6 +210,7 @@ export class InstantRecordingUploader {
(error: CancelledUploadError) => void
>();
private readonly stallTimeouts = new Set<number>();
+ private processingStarted = true;
constructor(options: {
videoId: VideoId;
@@ -706,7 +703,7 @@ export class InstantRecordingUploader {
throw new Error("No uploaded parts available for completion");
}
- await completeMultipartUpload(
+ const completionResult = await completeMultipartUpload(
this.videoId,
this.uploadId,
[...this.parts].sort((left, right) => left.partNumber - right.partNumber),
@@ -718,6 +715,7 @@ export class InstantRecordingUploader {
subpath: options.subpath,
},
);
+ this.processingStarted = completionResult.processingStarted;
this.finished = true;
this.uploadedBytes = this.finalTotalBytes ?? this.uploadedBytes;
@@ -730,6 +728,10 @@ export class InstantRecordingUploader {
await this.sendProgressUpdate(this.uploadedBytes, this.uploadedBytes);
}
+ getProcessingStarted() {
+ return this.processingStarted;
+ }
+
async cancel() {
if (this.finished) return;
this.cancelled = true;
diff --git a/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/useWebRecorder.ts b/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/useWebRecorder.ts
index e90edd57b..9acf4e24f 100644
--- a/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/useWebRecorder.ts
+++ b/apps/web/app/(org)/dashboard/caps/components/web-recorder-dialog/useWebRecorder.ts
@@ -15,7 +15,6 @@ import {
InstantRecordingUploader,
initiateMultipartUpload,
MultipartCompletionUncertainError,
- ProcessingStartError,
} from "./instant-mp4-uploader";
import type { RecordingMode } from "./RecordingModeSelector";
import { captureThumbnail, convertToMp4 } from "./recording-conversion";
@@ -1223,6 +1222,12 @@ export const useWebRecorder = ({
fps,
subpath: rawSubpath,
});
+
+ if (!uploader.getProcessingStarted()) {
+ toast.warning(
+ "Recording uploaded. Processing did not start yet, but the original recording is available.",
+ );
+ }
} else {
const processedRecordingBlob =
pipeline.fileExtension === "mp4"
@@ -1359,20 +1364,6 @@ export const useWebRecorder = ({
console.error("Failed to process recording", err);
setUploadStatus(undefined);
const failureBlob = await resolveFailureBlob(rawRecordingBlob);
- if (err instanceof ProcessingStartError) {
- instantUploaderRef.current = null;
- recordingPipelineRef.current = null;
- pendingInstantVideoIdRef.current = null;
- videoCreationRef.current = null;
- replaceErrorDownload(failureBlob);
- await disposeRecordingSpool();
- updatePhase("error");
- toast.error(
- "Recording uploaded, but processing could not start. Open the video to retry processing.",
- );
- router.refresh();
- return;
- }
if (err instanceof MultipartCompletionUncertainError) {
instantUploaderRef.current = null;
recordingPipelineRef.current = null;