(videoId: string)
| 62 | } |
| 63 | |
| 64 | export async function invalidateVideoCache(videoId: string) { |
| 65 | await requireAdmin(); |
| 66 | const video = await getVideoOrThrow(videoId); |
| 67 | |
| 68 | if (video.bucket) { |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | const distributionId = serverEnv().CAP_CLOUDFRONT_DISTRIBUTION_ID; |
| 73 | if (!distributionId) { |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | const fileKey = `${video.ownerId}/${video.id}/result.mp4`; |
| 78 | |
| 79 | const cloudfront = new CloudFrontClient({ |
| 80 | region: serverEnv().CAP_AWS_REGION || "us-east-1", |
| 81 | credentials: await runPromise( |
| 82 | Effect.map(AwsCredentials, (c) => c.credentials), |
| 83 | ), |
| 84 | }); |
| 85 | |
| 86 | await cloudfront.send( |
| 87 | new CreateInvalidationCommand({ |
| 88 | DistributionId: distributionId, |
| 89 | InvalidationBatch: { |
| 90 | CallerReference: `${Date.now()}`, |
| 91 | Paths: { |
| 92 | Quantity: 1, |
| 93 | Items: [`/${fileKey}`], |
| 94 | }, |
| 95 | }, |
| 96 | }), |
| 97 | ); |
| 98 | } |
no test coverage detected