MCPcopy
hub / github.com/CapSoftware/Cap / importLoomVideoForOwner

Function importLoomVideoForOwner

apps/web/actions/loom.ts:316–452  ·  view source on GitHub ↗
({
	loomUrl,
	orgId,
	ownerId,
}: {
	loomUrl: string;
	orgId: Organisation.OrganisationId;
	ownerId: User.UserId;
})

Source from the content-addressed store, hash-verified

314}
315
316async function importLoomVideoForOwner({
317 loomUrl,
318 orgId,
319 ownerId,
320}: {
321 loomUrl: string;
322 orgId: Organisation.OrganisationId;
323 ownerId: User.UserId;
324}): Promise<LoomImportResult> {
325 const loomVideoId = extractLoomVideoId(loomUrl.trim());
326 if (!loomVideoId) {
327 return {
328 success: false,
329 error:
330 "Invalid Loom URL. Please paste a valid Loom video link (e.g. https://www.loom.com/share/abc123).",
331 };
332 }
333
334 const existing = await db()
335 .select({
336 videoId: videos.id,
337 })
338 .from(importedVideos)
339 .leftJoin(
340 videos,
341 and(
342 eq(videos.id, importedVideos.id),
343 eq(videos.orgId, importedVideos.orgId),
344 ),
345 )
346 .where(
347 and(
348 eq(importedVideos.orgId, orgId),
349 eq(importedVideos.source, "loom"),
350 eq(importedVideos.sourceId, loomVideoId),
351 ),
352 );
353
354 if (existing.some((row) => row.videoId !== null)) {
355 return {
356 success: false,
357 error: "This Loom video has already been imported.",
358 };
359 }
360
361 if (existing.length > 0) {
362 await db()
363 .delete(importedVideos)
364 .where(
365 and(
366 eq(importedVideos.orgId, orgId),
367 eq(importedVideos.source, "loom"),
368 eq(importedVideos.sourceId, loomVideoId),
369 ),
370 );
371 }
372
373 const downloadUrl = await getLoomDownloadUrl(loomVideoId);

Callers 2

importFromLoomFunction · 0.85
importFromLoomCsvFunction · 0.85

Calls 9

dbFunction · 0.90
serverEnvFunction · 0.90
dubFunction · 0.90
startFunction · 0.90
extractLoomVideoIdFunction · 0.70
getLoomDownloadUrlFunction · 0.70
fetchVideoNameFunction · 0.70
fetchLoomOEmbedFunction · 0.70
createMethod · 0.45

Tested by

no test coverage detected