Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(mobile): extend mobile API client for recordings
Richie McIlroye605ae73e68e
diff --git a/apps/mobile/src/api/mobile.test.ts b/apps/mobile/src/api/mobile.test.tsindex 1a66a6a95..346226ba5 100644--- a/apps/mobile/src/api/mobile.test.ts+++ b/apps/mobile/src/api/mobile.test.ts@@ -282,6 +282,67 @@ describe("createMobileApiClient", () => {}});+ it("requests segmented recording targets and completes separate media tracks", async () => {+ const calls: Array<{ input: RequestInfo | URL; init?: RequestInit }> = [];+ const originalFetch = globalThis.fetch;+ globalThis.fetch = (async (+ input: RequestInfo | URL,+ init?: RequestInit,+ ) => {+ calls.push({ input, init });+ if (String(input).endsWith("/segments/targets")) {+ return new Response(+ JSON.stringify({+ uploads: {+ "segments/video/init.mp4": {+ type: "put",+ url: "https://uploads.example/video-init",+ headers: { "Content-Type": "video/mp4" },+ },+ },+ }),+ { status: 200 },+ );+ }+ return new Response(JSON.stringify({ success: true }), { status: 200 });+ }) as typeof fetch;++ try {+ const client = createMobileApiClient({+ baseUrl: "https://cap.so/",+ getToken: () => "api-key",+ });+ const targets = await client.createRecordingUploadTargets("video_123", [+ "segments/video/init.mp4",+ ]);+ await client.completeRecording("video_123", {+ durationSeconds: 2,+ totalBytes: 650_500,+ videoSegments: [{ index: 1, duration: 2 }],+ audioSegments: [{ index: 1, duration: 2 }],+ });++ expect(targets.uploads["segments/video/init.mp4"]?.type).toBe("put");+ expect(String(calls[0]?.input)).toBe(+ "https://cap.so/api/mobile/recordings/video_123/segments/targets",+ );+ expect(JSON.parse(calls[0]?.init?.body as string)).toEqual({+ subpaths: ["segments/video/init.mp4"],+ });+ expect(String(calls[1]?.input)).toBe(+ "https://cap.so/api/mobile/recordings/video_123/complete",+ );+ expect(JSON.parse(calls[1]?.init?.body as string)).toEqual({+ durationSeconds: 2,+ totalBytes: 650_500,+ videoSegments: [{ index: 1, duration: 2 }],+ audioSegments: [{ index: 1, duration: 2 }],+ });+ } finally {+ globalThis.fetch = originalFetch;+ }+ });+it("updates Cap passwords with the authenticated PATCH endpoint", async () => {const calls: Array<{ input: RequestInfo | URL; init?: RequestInit }> = [];const originalFetch = globalThis.fetch;diff --git a/apps/mobile/src/api/mobile.ts b/apps/mobile/src/api/mobile.tsindex da87e70c6..4f979b5f0 100644--- a/apps/mobile/src/api/mobile.ts+++ b/apps/mobile/src/api/mobile.ts@@ -24,6 +24,12 @@ export type MobileUploadCreateInput =typeof Mobile.MobileUploadCreateInput.Type;export type MobileUploadCreateResponse =typeof Mobile.MobileUploadCreateResponse.Type;+export type MobileRecordingCreateInput =+ typeof Mobile.MobileRecordingCreateInput.Type;+export type MobileRecordingCreateResponse =+ typeof Mobile.MobileRecordingCreateResponse.Type;+export type MobileRecordingCompleteInput =+ typeof Mobile.MobileRecordingCompleteInput.Type;export type MobileApiClient = ReturnType<typeof createMobileApiClient>;@@ -297,6 +303,29 @@ export const createMobileApiClient = ({ baseUrl, getToken }: ClientOptions) => {body: input,},),+ createRecording: (input: MobileRecordingCreateInput) =>+ request("/api/mobile/recordings", Mobile.MobileRecordingCreateResponse, {+ method: "POST",+ body: input,+ }),+ createRecordingUploadTargets: (id: string, subpaths: string[]) =>+ request(+ `/api/mobile/recordings/${id}/segments/targets`,+ Mobile.MobileRecordingUploadTargetsResponse,+ {+ method: "POST",+ body: { subpaths },+ },+ ),+ completeRecording: (id: string, input: MobileRecordingCompleteInput) =>+ request(+ `/api/mobile/recordings/${id}/complete`,+ Mobile.MobileSuccessResponse,+ {+ method: "POST",+ body: input,+ },+ ),revokeSession: () =>request("/api/mobile/session/revoke", Mobile.MobileSuccessResponse, {method: "POST",