Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(web): address editor review feedback
Richie McIlroy0ed699f7abad
diff --git a/apps/media-server/src/__tests__/routes/video.test.ts b/apps/media-server/src/__tests__/routes/video.test.tsindex 8ea9b5656..a04723230 100644--- a/apps/media-server/src/__tests__/routes/video.test.ts+++ b/apps/media-server/src/__tests__/routes/video.test.ts@@ -484,6 +484,20 @@ describe("POST /video/edit", () => {expect(response.status).toBe(401);});+ test("returns 400 for invalid JSON", async () => {+ const response = await app.fetch(+ new Request("http://localhost/video/edit", {+ method: "POST",+ headers: AUTH_HEADERS,+ body: "{",+ }),+ );++ expect(response.status).toBe(400);+ const data = await response.json();+ expect(data.code).toBe("INVALID_REQUEST");+ });+test("returns 400 for missing keep ranges", async () => {const response = await app.fetch(videoPostRequest("/video/edit", {diff --git a/apps/media-server/src/routes/video.ts b/apps/media-server/src/routes/video.tsindex 5fb8a9d96..fb44df309 100644--- a/apps/media-server/src/routes/video.ts+++ b/apps/media-server/src/routes/video.ts@@ -534,7 +534,12 @@ video.post("/edit", async (c) => {return c.json({ error: "Unauthorized" }, 401);}- const body = await c.req.json();+ let body: unknown;+ try {+ body = await c.req.json();+ } catch {+ return c.json({ error: "Invalid request", code: "INVALID_REQUEST" }, 400);+ }const result = editSchema.safeParse(body);if (!result.success) {@@ -728,7 +733,12 @@ async function processWithResilientRetry(updateJob(jobId, { progress: scaledProgress, message });const currentJob = getJob(jobId);if (currentJob) {- sendWebhook(currentJob);+ void sendWebhook(currentJob).catch((error) =>+ console.warn(+ `[video/process] Failed to send webhook update for job ${jobId}:`,+ error,+ ),+ );}};@@ -856,8 +866,7 @@ async function editVideoAsync(previewGifPresignedUrl: string | undefined,options: z.infer<typeof editSchema>,): Promise<void> {- const job = getJob(jobId);- if (!job) {+ if (!getJob(jobId)) {return;}@@ -870,7 +879,10 @@ async function editVideoAsync(progress: 0,message: "Downloading source video...",});- await sendWebhook(job);+ const downloadingJob = getJob(jobId);+ if (downloadingJob) {+ await sendWebhook(downloadingJob);+ }const inputTempFile = await downloadVideoToTemp(sourceUrl,@@ -884,7 +896,10 @@ async function editVideoAsync(progress: 5,message: "Analyzing source video...",});- await sendWebhook(job);+ const probingJob = getJob(jobId);+ if (probingJob) {+ await sendWebhook(probingJob);+ }const sourceMetadata = await probeVideoFile(inputTempFile.path);@@ -893,7 +908,10 @@ async function editVideoAsync(progress: 10,message: "Applying edit...",});- await sendWebhook(job);+ const processingJob = getJob(jobId);+ if (processingJob) {+ await sendWebhook(processingJob);+ }const outputTempFile = await withJobHeartbeat(jobId, () =>renderEditedVideo({@@ -908,7 +926,12 @@ async function editVideoAsync(});const currentJob = getJob(jobId);if (currentJob) {- sendWebhook(currentJob);+ void sendWebhook(currentJob).catch((error) =>+ console.warn(+ `[video/edit] Failed to send webhook update for job ${jobId}:`,+ error,+ ),+ );}},}),@@ -923,7 +946,10 @@ async function editVideoAsync(progress: 80,message: "Uploading edited video...",});- await sendWebhook(job);+ const uploadingJob = getJob(jobId);+ if (uploadingJob) {+ await sendWebhook(uploadingJob);+ }await uploadFileToS3(outputTempFile.path, outputPresignedUrl, "video/mp4");@@ -933,7 +959,10 @@ async function editVideoAsync(progress: 90,message: "Generating preview assets...",});- await sendWebhook(job);+ const thumbnailJob = getJob(jobId);+ if (thumbnailJob) {+ await sendWebhook(thumbnailJob);+ }}if (thumbnailPresignedUrl) {@@ -975,14 +1004,20 @@ async function editVideoAsync(message: "Edit failed",});- if (updatedJob) {- await sendWebhook(updatedJob);- }+ try {+ if (updatedJob) {+ await sendWebhook(updatedJob);+ }+ } finally {+ const currentJob = getJob(jobId);+ if (currentJob) {+ await Promise.allSettled([+ currentJob.inputTempFile?.cleanup(),+ currentJob.outputTempFile?.cleanup(),+ ]);+ }- const currentJob = getJob(jobId);- if (currentJob) {- await currentJob.inputTempFile?.cleanup();- await currentJob.outputTempFile?.cleanup();+ setTimeout(() => deleteJob(jobId), 5 * 60 * 1000);}}}diff --git a/apps/web/app/api/webhooks/media-server/progress/route.ts b/apps/web/app/api/webhooks/media-server/progress/route.tsindex 332fda280..509572aee 100644--- a/apps/web/app/api/webhooks/media-server/progress/route.ts+++ b/apps/web/app/api/webhooks/media-server/progress/route.ts@@ -179,6 +179,7 @@ export async function POST(request: NextRequest) {phase: "complete",processingProgress: 100,processingMessage: payload.message,+ processingError: null,updatedAt: new Date(),}).where(eq(videoUploads.videoId, payload.videoId as Video.VideoId));diff --git a/apps/web/app/s/[videoId]/Share.tsx b/apps/web/app/s/[videoId]/Share.tsxindex 5d7e9dd3d..1e2b5a851 100644--- a/apps/web/app/s/[videoId]/Share.tsx+++ b/apps/web/app/s/[videoId]/Share.tsx@@ -149,6 +149,7 @@ interface ShareProps {videoSettings?: OrganizationSettings | null;userOrganizations?: { id: string; name: string }[];viewerId?: string | null;+ isEditProcessing: boolean;initialAiData?: {title?: string | null;summary?: string | null;@@ -261,6 +262,7 @@ export const Share = ({aiGenerationEnabled,videoSettings,viewerId,+ isEditProcessing,}: ShareProps) => {const effectiveDate: Date = data.metadata?.customCreatedAt? new Date(data.metadata.customCreatedAt)@@ -480,6 +482,7 @@ export const Share = ({aiGenerationStatus={aiData?.aiGenerationStatus}canRetryProcessing={viewerId === data.owner.id}showPlaybackStatusBadge={viewerId === data.owner.id}+ isEditProcessing={isEditProcessing}ref={playerRef}/></div>diff --git a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx b/apps/web/app/s/[videoId]/_components/ShareVideo.tsxindex a6096d3e9..6907dcf3b 100644--- a/apps/web/app/s/[videoId]/_components/ShareVideo.tsx+++ b/apps/web/app/s/[videoId]/_components/ShareVideo.tsx@@ -51,6 +51,7 @@ export const ShareVideo = forwardRef<aiGenerationStatus?: AiGenerationStatus | null;canRetryProcessing?: boolean;showPlaybackStatusBadge?: boolean;+ isEditProcessing: boolean;}>((@@ -64,6 +65,7 @@ export const ShareVideo = forwardRef<areReactionStampsDisabled,canRetryProcessing,showPlaybackStatusBadge = false,+ isEditProcessing,},ref,) => {@@ -194,9 +196,6 @@ export const ShareVideo = forwardRef<const isMp4Source =data.source.type === "desktopMP4" || data.source.type === "webMP4";const isSegmentsSource = data.source.type === "desktopSegments";- const isEditProcessing =- data.activeUploadRawFileKey ===- `${data.owner.id}/${data.id}/source/original.mp4`;const isActivelyRecording =isSegmentsSource &&(data.hasActiveUpload ?? false) &&diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsxindex 53e7b1013..bc4acf723 100644--- a/apps/web/app/s/[videoId]/page.tsx+++ b/apps/web/app/s/[videoId]/page.tsx@@ -48,7 +48,10 @@ import {SOCIAL_REFERRER_DOMAINS,} from "@/lib/social-crawlers";import { transcribeVideo } from "@/lib/transcribe";-import { reconcileStaleEditUpload } from "@/lib/video-edit-processing";+import {+ isEditSourceKey,+ reconcileStaleEditUpload,+} from "@/lib/video-edit-processing";import { optionFromTOrFirst } from "@/utils/effect";import { isAiGenerationEnabled } from "@/utils/flags";import { PasswordOverlay } from "./_components/PasswordOverlay";@@ -695,6 +698,11 @@ async function AuthorizedContent({inheritedSpaceSettings: rules.inheritedSettings,};}).pipe(runPromise);+ const isEditProcessing = isEditSourceKey({+ ownerId: video.owner.id,+ videoId,+ rawFileKey: video.activeUploadRawFileKey,+ });return (<>@@ -725,6 +733,7 @@ async function AuthorizedContent({domainVerified={domainVerified}userOrganizations={userOrganizations}viewerId={user?.id ?? null}+ isEditProcessing={isEditProcessing}initialAiData={initialAiData}aiGenerationEnabled={aiGenerationEnabled}/>diff --git a/apps/web/lib/video-edit-processing.ts b/apps/web/lib/video-edit-processing.tsindex b82227d2d..ac818cc40 100644--- a/apps/web/lib/video-edit-processing.ts+++ b/apps/web/lib/video-edit-processing.ts@@ -5,7 +5,7 @@ import { eq } from "drizzle-orm";const SECOND = 1000;const MINUTE = 60 * SECOND;-const STALE_EDIT_PROCESSING_START_MS = 2 * MINUTE;+const STALE_EDIT_PROCESSING_START_MS = 15 * MINUTE;const STALE_EDIT_PROCESSING_PROGRESS_MS = 10 * MINUTE;const STALE_EDIT_THUMBNAIL_MS = 5 * MINUTE;