( videoId: string, editSpec: VideoEditSpec, )
| 603 | } |
| 604 | |
| 605 | async function invalidateEditedVideoCache( |
| 606 | videoId: string, |
| 607 | editSpec: VideoEditSpec, |
| 608 | ): Promise<void> { |
| 609 | "use step"; |
| 610 | |
| 611 | const distributionId = serverEnv().CAP_CLOUDFRONT_DISTRIBUTION_ID; |
| 612 | if (!distributionId) return; |
| 613 | |
| 614 | const [video] = await db() |
| 615 | .select({ |
| 616 | ownerId: videos.ownerId, |
| 617 | bucket: videos.bucket, |
| 618 | }) |
| 619 | .from(videos) |
| 620 | .where(eq(videos.id, videoId as Video.VideoId)); |
| 621 | |
| 622 | if (!video || video.bucket) return; |
| 623 | |
| 624 | const basePath = `/${video.ownerId}/${videoId}`; |
| 625 | const paths = [ |
| 626 | `${basePath}/result.mp4`, |
| 627 | `${basePath}/screenshot/screen-capture.jpg`, |
| 628 | `${basePath}/preview/animated-preview.gif`, |
| 629 | ]; |
| 630 | |
| 631 | try { |
| 632 | const cloudfront = new CloudFrontClient({ |
| 633 | region: serverEnv().CAP_AWS_REGION || "us-east-1", |
| 634 | credentials: await runPromise( |
| 635 | Effect.map(AwsCredentials, (credentials) => credentials.credentials), |
| 636 | ), |
| 637 | }); |
| 638 | |
| 639 | await cloudfront.send( |
| 640 | new CreateInvalidationCommand({ |
| 641 | DistributionId: distributionId, |
| 642 | InvalidationBatch: { |
| 643 | CallerReference: getEditInvalidationCallerReference( |
| 644 | videoId, |
| 645 | editSpec, |
| 646 | ), |
| 647 | Paths: { |
| 648 | Quantity: paths.length, |
| 649 | Items: paths, |
| 650 | }, |
| 651 | }, |
| 652 | }), |
| 653 | ); |
| 654 | } catch (error) { |
| 655 | console.warn( |
| 656 | "[editVideoWorkflow] Failed to invalidate edited video cache", |
| 657 | { |
| 658 | error, |
| 659 | videoId, |
| 660 | }, |
| 661 | ); |
| 662 | } |
no test coverage detected