Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix: handle long titles and large Loom downloads
Richie McIlroy9a04ef545040
diff --git a/apps/media-server/src/__tests__/lib/loom-import-limit.test.ts b/apps/media-server/src/__tests__/lib/loom-import-limit.test.tsindex b7aa589db..cb5aa9a29 100644--- a/apps/media-server/src/__tests__/lib/loom-import-limit.test.ts+++ b/apps/media-server/src/__tests__/lib/loom-import-limit.test.ts@@ -1,4 +1,4 @@-import { afterEach, describe, expect, test } from "bun:test";+import { afterEach, describe, expect, spyOn, test } from "bun:test";import { execFileSync } from "node:child_process";import { mkdtemp, rm } from "node:fs/promises";import { tmpdir } from "node:os";@@ -69,6 +69,29 @@ describe("Loom import file size", () => {expect(cancelled).toBe(true);});+ test.each([+ ["bounded Loom downloads", 16, 30 * 60 * 1000],+ ["ordinary downloads", undefined, 10 * 60 * 1000],+ ])("keeps the expected timeout for %s", async (_, maxBytes, timeoutMs) => {+ const timeoutSpy = spyOn(AbortSignal, "timeout");+ stubFetch(async () => new Response(new Uint8Array(16)));+ try {+ const result = await downloadVideoToTemp(+ "https://source.test/video.mp4",+ ".mp4",+ undefined,+ maxBytes,+ );+ try {+ expect(timeoutSpy).toHaveBeenCalledWith(timeoutMs);+ } finally {+ await result.cleanup();+ }+ } finally {+ timeoutSpy.mockRestore();+ }+ });+test("enforces the import limit when parallel downloads are enabled", async () => {process.env.MEDIA_SERVER_DOWNLOAD_CONCURRENCY = "4";stubFetch(async () => new Response(new Uint8Array(17)));diff --git a/apps/media-server/src/lib/media-video.ts b/apps/media-server/src/lib/media-video.tsindex a208e9b7e..f65a33d68 100644--- a/apps/media-server/src/lib/media-video.ts+++ b/apps/media-server/src/lib/media-video.ts@@ -60,7 +60,7 @@ const MAX_PROCESS_TIMEOUT_MS = 2 * 60 * 60 * 1000;// flat 10-minute budget is enough for typical short recordings but not for a// long (e.g. 60+ minute) manifest with 1000+ segments.const STREAMING_DOWNLOAD_TIMEOUT_PER_SECOND_MS = 5_000;-const MAX_STREAMING_DOWNLOAD_TIMEOUT_MS = 30 * 60 * 1000;+const MAX_DOWNLOAD_TIMEOUT_MS = 30 * 60 * 1000;const THUMBNAIL_TIMEOUT_MS = 60_000;const PREVIEW_GIF_TIMEOUT_MS = 30_000;const PROBE_H264_LEVEL_TIMEOUT_MS = 10_000;@@ -1196,7 +1196,7 @@ function getStreamingDownloadTimeoutMs(durationSeconds: number | null): number {if (!durationSeconds) return DOWNLOAD_TIMEOUT_MS;return Math.min(- MAX_STREAMING_DOWNLOAD_TIMEOUT_MS,+ MAX_DOWNLOAD_TIMEOUT_MS,Math.max(DOWNLOAD_TIMEOUT_MS,Math.ceil(durationSeconds * STREAMING_DOWNLOAD_TIMEOUT_PER_SECOND_MS),@@ -1294,7 +1294,9 @@ export async function downloadVideoToTemp();try {- const timeoutSignal = AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS);+ const timeoutSignal = AbortSignal.timeout(+ maxBytes === undefined ? DOWNLOAD_TIMEOUT_MS : MAX_DOWNLOAD_TIMEOUT_MS,+ );const combinedSignal = abortSignal? AbortSignal.any([abortSignal, timeoutSignal]): timeoutSignal;diff --git a/apps/web/__tests__/unit/loom-import.test.ts b/apps/web/__tests__/unit/loom-import.test.tsindex 274457c1a..c4db9288b 100644--- a/apps/web/__tests__/unit/loom-import.test.ts+++ b/apps/web/__tests__/unit/loom-import.test.ts@@ -602,6 +602,49 @@ describe("importFromLoom", () => {expect(valuesMock).not.toHaveBeenCalled();});+ it.each([+ ["long titles", "a".repeat(383), "a".repeat(255)],+ ["Unicode titles", "π₯".repeat(260), "π₯".repeat(255)],+ ["short titles", "Imported π₯ video", "Imported π₯ video"],+ ])(+ "fits %s into the destination without changing the import",+ async (_, title, expected) => {+ valuesMock.mockImplementation(async (value: { name?: string }) => {+ if (value.name && Array.from(value.name).length > 255) {+ throw new Error("Data too long for column name");+ }+ });+ vi.mocked(fetch).mockImplementation(async (input) => {+ const url = input.toString();+ if (url.includes("/transcoded-url")) {+ return Response.json({ url: "https://cdn.loom.com/video.mp4" });+ }+ if (url === "https://www.loom.com/graphql") {+ return Response.json({ data: { getVideo: { name: title } } });+ }+ if (url.includes("/v1/oembed")) {+ return Response.json({ duration: 42, width: 1920, height: 1080 });+ }+ throw new Error(`Unexpected fetch: ${url}`);+ });+ const { importFromLoom } = await import("@/actions/loom");+ expect(+ await importFromLoom({+ loomUrl: "https://www.loom.com/share/loom-abc1234567",+ orgId: "org-1" as Organisation.OrganisationId,+ }),+ ).toEqual({ success: true, videoId: "video-123" });+ expect(valuesMock).toHaveBeenCalledWith(+ expect.objectContaining({+ name: expected,+ ownerId: "user-123",+ orgId: "org-1",+ }),+ );+ expect(startMock).toHaveBeenCalledTimes(1);+ },+ );+it("does not call the Vercel firewall from the Loom import server action", async () => {checkRateLimitMock.mockResolvedValueOnce({ rateLimited: true });diff --git a/apps/web/actions/loom.ts b/apps/web/actions/loom.tsindex 09120edfe..035a3f864 100644--- a/apps/web/actions/loom.ts+++ b/apps/web/actions/loom.ts@@ -116,6 +116,7 @@ export interface LoomCsvImportResult {const MAX_LOOM_CSV_ROWS = 500;const MAX_LOOM_SPACE_NAME_LENGTH = 255;+const MAX_LOOM_VIDEO_NAME_LENGTH = 255;const LOOM_CSV_LIMIT_ERROR = `CSV imports are limited to ${MAX_LOOM_CSV_ROWS} rows at a time. Contact support to raise this limit.`;const LOOM_CSV_PERMISSION_ERROR ="Only organization admins and owners can import Loom videos from a CSV.";@@ -526,9 +527,12 @@ async function importLoomVideoForOwner({const writable = writableResult.value;const videoId = Video.VideoId.make(nanoId());- const name =+ const name = Array.from(videoName ||- `Loom Import - ${new Date().toLocaleDateString("en-US", { day: "numeric", month: "long", year: "numeric" })}`;+ `Loom Import - ${new Date().toLocaleDateString("en-US", { day: "numeric", month: "long", year: "numeric" })}`,+ )+ .slice(0, MAX_LOOM_VIDEO_NAME_LENGTH)+ .join("");const claimedAt = new Date(Math.floor(Date.now() / 1000) * 1000);await db().transaction(async (tx) => {