MCPcopy Index your code
hub / github.com/CapSoftware/Cap / invalidateEditedVideoCache

Function invalidateEditedVideoCache

apps/web/workflows/edit-video.ts:605–663  ·  view source on GitHub ↗
(
	videoId: string,
	editSpec: VideoEditSpec,
)

Source from the content-addressed store, hash-verified

603}
604
605async 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 }

Callers 1

editVideoWorkflowFunction · 0.85

Calls 5

serverEnvFunction · 0.90
dbFunction · 0.90
runPromiseFunction · 0.90
sendMethod · 0.45

Tested by

no test coverage detected