Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat: let operator Loom imports land in the owner's folders
Richie McIlroy41a3da71f135
diff --git a/apps/web/__tests__/unit/loom-operator-tools.test.ts b/apps/web/__tests__/unit/loom-operator-tools.test.tsindex 357e03434..a2df47179 100644--- a/apps/web/__tests__/unit/loom-operator-tools.test.ts+++ b/apps/web/__tests__/unit/loom-operator-tools.test.ts@@ -243,6 +243,7 @@ describe("operator CSV import", () => {rows: [{ ...body.rows[0], spaceName: "" }],orgId: ids.org,actorId: "owneraaaaaaaaaa",+ allowFolders: true,});});diff --git a/apps/web/app/api/internal/loom-imports/csv/route.ts b/apps/web/app/api/internal/loom-imports/csv/route.tsindex 271d9948a..92c2b068d 100644--- a/apps/web/app/api/internal/loom-imports/csv/route.ts+++ b/apps/web/app/api/internal/loom-imports/csv/route.ts@@ -35,6 +35,9 @@ class Api extends HttpApi.make("LoomOperatorCsvImportApi").add(spaceName: Schema.optional(Schema.String.pipe(Schema.maxLength(255)),),+ folderName: Schema.optional(+ Schema.String.pipe(Schema.maxLength(255)),+ ),}),).pipe(Schema.minItems(1), Schema.maxItems(MAX_ROWS_PER_REQUEST)),}),@@ -107,9 +110,11 @@ const ApiLive = HttpApiBuilder.api(Api).pipe(loomUrl: row.loomUrl,userEmail: row.userEmail,spaceName: row.spaceName ?? "",+ folderName: row.folderName,})),orgId: organizationId,actorId: organization.ownerId,+ allowFolders: true,}),);return {diff --git a/apps/web/lib/loom-csv-import.ts b/apps/web/lib/loom-csv-import.tsindex 6d2825f28..3ebc09202 100644--- a/apps/web/lib/loom-csv-import.ts+++ b/apps/web/lib/loom-csv-import.ts@@ -3,6 +3,7 @@ import "server-only";import { db } from "@cap/database";import { nanoId } from "@cap/database/helpers";import {+ folders,importedVideos,loomMigrationImports,loomMigrationRequests,@@ -20,13 +21,14 @@ import { buildEnv, NODE_ENV, serverEnv } from "@cap/env";import { dub } from "@cap/utils";import { Storage } from "@cap/web-backend";import {+ Folder,type Organisation,Space,SpaceMemberId,type User,Video,} from "@cap/web-domain";-import { and, eq, sql } from "drizzle-orm";+import { and, asc, eq, isNull, sql } from "drizzle-orm";import { Option } from "effect";import { revalidatePath } from "next/cache";import { renewConciergeImport } from "@/lib/loom-concierge";@@ -75,6 +77,7 @@ export interface LoomCsvImportRow {loomUrl: string;userEmail: string;spaceName?: string;+ folderName?: string;}export interface LoomCsvImportRowResult {@@ -732,18 +735,58 @@ export async function addImportOwnerToSpace({});}+async function getOrCreatePersonalImportFolder({+ orgId,+ ownerId,+ name,+}: {+ orgId: Organisation.OrganisationId;+ ownerId: User.UserId;+ name: string;+}) {+ const match = () =>+ db()+ .select({ id: folders.id })+ .from(folders)+ .where(+ and(+ eq(folders.organizationId, orgId),+ eq(folders.createdById, ownerId),+ eq(folders.name, name),+ isNull(folders.spaceId),+ isNull(folders.parentId),+ ),+ )+ .orderBy(asc(folders.createdAt))+ .limit(1);+ const [existing] = await match();+ if (existing) return existing.id;+ await db()+ .insert(folders)+ .values({+ id: Folder.FolderId.make(nanoId()),+ name,+ organizationId: orgId,+ createdById: ownerId,+ });+ const [created] = await match();+ return created?.id;+}+export async function processLoomCsvRows({rows,orgId,actorId,migrationRequestId,migrationLeaseToken,+ allowFolders = false,}: {rows: LoomCsvImportRow[];orgId: Organisation.OrganisationId;actorId: User.UserId;migrationRequestId?: string;migrationLeaseToken?: string;+ allowFolders?: boolean;}): Promise<LoomCsvImportResult> {const inputRows = Array.isArray(rows) ? rows : [];const normalizedRows = inputRows@@ -761,6 +804,10 @@ export async function processLoomCsvRows({typeof row.spaceName === "string"? normalizeImportSpaceName(row.spaceName): "",+ folderName:+ allowFolders && typeof row.folderName === "string"+ ? normalizeImportSpaceName(row.folderName)+ : "",})).filter((row) => row.loomUrl || row.userEmail || row.spaceName);@@ -857,10 +904,18 @@ export async function processLoomCsvRows({}try {+ const folderId = row.folderName+ ? await getOrCreatePersonalImportFolder({+ orgId,+ ownerId: member.userId,+ name: row.folderName,+ })+ : undefined;const result = await importLoomVideoForOwner({loomUrl: row.loomUrl,orgId,ownerId: member.userId,+ destination: folderId ? { folderId } : {},migrationRequestId,migrationLeaseToken,});