| 107 | } |
| 108 | |
| 109 | async function waitForInvalidations(Id) { |
| 110 | await new Promise((r) => setTimeout(r, 3000)) |
| 111 | const { |
| 112 | Invalidation: { Status }, |
| 113 | } = await cloudfront.send( |
| 114 | new GetInvalidationCommand({ |
| 115 | DistributionId: distributionId, |
| 116 | Id, |
| 117 | }) |
| 118 | ) |
| 119 | if (Status === 'Completed') { |
| 120 | return true |
| 121 | } |
| 122 | msg.loader.start( |
| 123 | `Invalidating stale assets... (${ |
| 124 | Status === 'InProgress' ? 'in progress' : Status |
| 125 | })` |
| 126 | ) |
| 127 | return await waitForInvalidations(Id) |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Upload an individual file to s3. |