({
loomUrl,
orgId,
ownerId,
}: {
loomUrl: string;
orgId: Organisation.OrganisationId;
ownerId: User.UserId;
})
| 314 | } |
| 315 | |
| 316 | async 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); |
no test coverage detected