Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(web): keep video durations and edit controls in folders

Akshar Patel151273ee7745
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index c6b940113..8dbe269e9 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -123,6 +123,7 @@ jobs:
run: >-
bun run --cwd apps/web test
__tests__/unit/embed-video-playback-chrome.test.ts
+ __tests__/unit/folder-videos.test.ts
__tests__/unit/homepage-demo-accessibility.test.ts
__tests__/unit/linkified-text.test.ts
__tests__/unit/loom-import-ui.test.ts
diff --git a/apps/web/__tests__/unit/folder-videos.test.ts b/apps/web/__tests__/unit/folder-videos.test.ts
new file mode 100644
index 000000000..ef699aba8
--- /dev/null
+++ b/apps/web/__tests__/unit/folder-videos.test.ts
@@ -0,0 +1,89 @@
+import { Database, ImageUploads } from "@cap/web-backend";
+import { Folder, Organisation, Space } from "@cap/web-domain";
+import { Effect } from "effect";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import { getVideosByFolderId } from "@/lib/folder";
+
+const mocks = vi.hoisted(() => ({ query: vi.fn() }));
+
+vi.mock("server-only", () => ({}));
+vi.mock("@cap/web-backend", async () => {
+ const { drizzle } = await import("drizzle-orm/mysql-proxy");
+ const { Effect } = await import("effect");
+ const { resolveEffectiveVideoRules } = await import(
+ "../../../../packages/web-backend/src/Videos/EffectiveVideoRules"
+ );
+ const client = drizzle(mocks.query);
+ class Database extends Effect.Service<Database>()("Database", {
+ succeed: {
+ use: <T>(callback: (db: typeof client) => Promise<T>) =>
+ Effect.promise(() => callback(client)),
+ },
+ }) {}
+ class ImageUploads extends Effect.Service<ImageUploads>()("ImageUploads", {
+ succeed: {
+ resolveImageUrl: (key: string) => Effect.succeed(key),
+ },
+ }) {}
+ return { Database, ImageUploads, resolveEffectiveVideoRules };
+});
+
+beforeEach(() => {
+ mocks.query.mockResolvedValue({ rows: [] });
+});
+
+describe.each([
+ { variant: "user" } as const,
+ { variant: "space", spaceId: Space.SpaceId.make("space-1") } as const,
+ {
+ variant: "org",
+ organizationId: Organisation.OrganisationId.make("org-1"),
+ } as const,
+])("$variant folder videos", (root) => {
+ it.each([125.5, null])(
+ "preserves a stored duration of %s",
+ async (duration) => {
+ mocks.query.mockResolvedValueOnce({
+ rows: [
+ [
+ "video-1",
+ "owner-1",
+ "Product walkthrough",
+ "2026-10-23 12:00:00",
+ true,
+ null,
+ { type: "webMP4" },
+ false,
+ duration,
+ null,
+ "org-1",
+ 0,
+ 0,
+ [],
+ "Owner",
+ "2026-10-23 12:00:00",
+ false,
+ false,
+ ],
+ ],
+ });
+ const videos = await getVideosByFolderId(
+ Folder.FolderId.make("folder-1"),
+ root,
+ ).pipe(
+ Effect.provide(Database.Default),
+ Effect.provide(ImageUploads.Default),
+ Effect.runPromise,
+ );
+
+ expect(videos).toMatchObject([
+ {
+ id: "video-1",
+ source: { type: "webMP4" },
+ duration: duration ?? undefined,
+ hasActiveUpload: false,
+ },
+ ]);
+ },
+ );
+});
diff --git a/apps/web/lib/folder.ts b/apps/web/lib/folder.ts
index 84fbc906a..aab98e4e1 100644
--- a/apps/web/lib/folder.ts
+++ b/apps/web/lib/folder.ts
@@ -338,6 +338,7 @@ export const getVideosByFolderId = Effect.fn(function* (
}
| undefined,
source: video.source,
+ duration: video.duration ?? undefined,
isScreenshot: video.isScreenshot,
hasPassword: video.hasPassword,
hasInheritedPassword: rules.hasInheritedPassword,