Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding cache buster to index.html #445 #451

Merged
merged 10 commits into from
Dec 28, 2023
12 changes: 6 additions & 6 deletions aatp/peerbook_webrtc/admin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ test.describe('peerbook administration', () => {
const fromPeerbook = await page.$$('.from-peerbook')
expect(fromPeerbook.length).toBe(0)
})
test('try login with an invalid email', async ({ browser }) => {
test('try subscribe with an invalid email', async ({ browser }) => {
// TODO: rename to context2
context = await browser.newContext()
page = await context.newPage()
Expand All @@ -261,7 +261,7 @@ test.describe('peerbook administration', () => {
await sleep(100)
if (await page.locator('[data-test="twr-minimized"]').isVisible())
await page.click('[data-test="twr-minimized"]')
await page.keyboard.type('login')
await page.keyboard.type('subscribe')
await page.keyboard.press("Enter")
await sleep(100)
let twr = await getTWRBuffer(page)
Expand All @@ -279,9 +279,9 @@ test.describe('peerbook administration', () => {
twr = await getTWRBuffer(page)
expect(twr).toMatch(/Invalid credentials/)
})
test('try login with an invalid OTP', async () => {
test('try subscribe with an invalid OTP', async () => {
await sleep(100)
await page.keyboard.type('login')
await page.keyboard.type('subscribe')
await page.keyboard.press("Enter")
await sleep(100)
let twr = await getTWRBuffer(page)
Expand All @@ -299,9 +299,9 @@ test.describe('peerbook administration', () => {
twr = await getTWRBuffer(page)
expect(twr).toMatch(/Invalid credentials/)
})
test('login with a valid email & OTP', async () => {
test('subscribe with a valid email & OTP', async () => {
await sleep(100)
await page.keyboard.type('login')
await page.keyboard.type('subscribe')
await page.keyboard.press("Enter")
await sleep(100)
let twr = await getTWRBuffer(page)
Expand Down
20 changes: 20 additions & 0 deletions cacheBuster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// cacheBuster.ts
function generateCacheBuster(): string {
// Find the main.ts script tag and remove it
const mainScript: HTMLScriptElement | null = document.querySelector('script[src*="main.ts"]');
if (mainScript) {
mainScript.remove();
}
shech2 marked this conversation as resolved.
Show resolved Hide resolved
// Generate a cache buster value based on the current timestamp
const currentTimestamp: number = Math.floor(Date.now() / 1000);
// Divide by 3600 to create a cache buster value that updates every hour
const cacheBusterValue: number = Math.floor(currentTimestamp / 3600);
return `?v=${cacheBusterValue}`;
}

// Set the src attribute for main.ts script
const script: HTMLScriptElement = document.createElement('script');
script.type = 'module';
script.src = `/main.ts${generateCacheBuster()}`;
document.head.appendChild(script);
shech2 marked this conversation as resolved.
Show resolved Hide resolved

1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,6 @@ <h1><span class="name"></span> Error</h1>
arrow_2_circlepath</i></button>
</nav>
</template>
<script type="text/javascript" src="/cacheBuster.ts"></script>
shech2 marked this conversation as resolved.
Show resolved Hide resolved
</body>
</html>