Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix: preserve loom csv retry quota
Tyler Gibbs46fe6434c204
diff --git a/apps/web/__tests__/unit/loom-import.test.ts b/apps/web/__tests__/unit/loom-import.test.tsindex 8b5b3f16a..98bf61372 100644--- a/apps/web/__tests__/unit/loom-import.test.ts+++ b/apps/web/__tests__/unit/loom-import.test.ts@@ -640,6 +640,99 @@ describe("importFromLoom", () => {expect(valuesMock).not.toHaveBeenCalled();});+ it("skips rate limit checks for csv rows that were already imported", async () => {+ whereMock.mockImplementation((conditions: unknown) => {+ const serializedConditions = JSON.stringify(conditions);++ if (serializedConditions.includes("sourceId")) {+ return Promise.resolve(+ serializedConditions.includes("loom-existing123")+ ? [{ videoId: "existing-video" }]+ : [],+ );+ }++ return withLimit([{ userId: "member-123", email: "[email protected]" }]);+ });++ const fetchMock = vi.mocked(fetch);+ fetchMock.mockImplementation(async (input) => {+ const url = typeof input === "string" ? input : input.toString();++ if (url.includes("/transcoded-url")) {+ return {+ ok: true,+ status: 200,+ text: async () =>+ JSON.stringify({ url: "https://cdn.loom.com/video.mp4" }),+ } as Response;+ }++ if (url === "https://www.loom.com/graphql") {+ return {+ ok: true,+ json: async () => ({+ data: { getVideo: { name: "Imported video" } },+ }),+ } as Response;+ }++ if (url.includes("/v1/oembed")) {+ return {+ ok: true,+ json: async () => ({ duration: 42, width: 1920, height: 1080 }),+ } as Response;+ }++ throw new Error(`Unexpected fetch: ${url}`);+ });++ const { importFromLoomCsv } = await import("@/actions/loom");++ const result = await importFromLoomCsv({+ orgId: "org-1" as never,+ rows: [+ {+ rowNumber: 2,+ loomUrl: "https://www.loom.com/share/loom-existing123",+ userEmail: "[email protected]",+ },+ {+ rowNumber: 3,+ loomUrl: "https://www.loom.com/share/loom-newvideo123",+ userEmail: "[email protected]",+ },+ ],+ });++ expect(result).toEqual({+ success: true,+ importedCount: 1,+ failedCount: 1,+ results: [+ {+ rowNumber: 2,+ userEmail: "[email protected]",+ spaceName: undefined,+ success: false,+ error: "This Loom video has already been imported.",+ },+ {+ rowNumber: 3,+ userEmail: "[email protected]",+ spaceName: undefined,+ success: true,+ videoId: "video-123",+ error: undefined,+ },+ ],+ error: undefined,+ });+ expect(checkRateLimitMock).toHaveBeenCalledTimes(1);+ expect(fetchMock).toHaveBeenCalled();+ expect(startMock).toHaveBeenCalledTimes(1);+ });+it("limits CSV imports to 500 rows", async () => {const fetchMock = vi.mocked(fetch);const { importFromLoomCsv } = await import("@/actions/loom");diff --git a/apps/web/actions/loom.ts b/apps/web/actions/loom.tsindex fc9bd4797..7d03ced00 100644--- a/apps/web/actions/loom.ts+++ b/apps/web/actions/loom.ts@@ -317,10 +317,12 @@ async function importLoomVideoForOwner({loomUrl,orgId,ownerId,+ isRateLimited,}: {loomUrl: string;orgId: Organisation.OrganisationId;ownerId: User.UserId;+ isRateLimited?: () => Promise<boolean>;}): Promise<LoomImportResult> {const loomVideoId = extractLoomVideoId(loomUrl.trim());if (!loomVideoId) {@@ -358,6 +360,13 @@ async function importLoomVideoForOwner({};}+ if (isRateLimited && (await isRateLimited())) {+ return {+ success: false,+ error: LOOM_IMPORT_RATE_LIMIT_ERROR,+ };+ }+if (existing.length > 0) {await db().delete(importedVideos)@@ -791,22 +800,12 @@ export async function importFromLoomCsv({}}- if (await isRateLimited()) {- results.push({- rowNumber: row.rowNumber,- userEmail: row.userEmail,- spaceName: row.spaceName || undefined,- success: false,- error: LOOM_IMPORT_RATE_LIMIT_ERROR,- });- continue;- }-try {const result = await importLoomVideoForOwner({loomUrl: row.loomUrl,orgId,ownerId: member.userId,+ isRateLimited,});let spaceName = row.spaceName || undefined;