cache versions
This commit is contained in:
@@ -12,6 +12,11 @@
|
||||
<!-- Canonical URL -->
|
||||
<link rel="canonical" href="https://music.quixy.uk/">
|
||||
|
||||
<!-- Cache Control for iOS -->
|
||||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
|
||||
<meta http-equiv="Pragma" content="no-cache">
|
||||
<meta http-equiv="Expires" content="0">
|
||||
|
||||
<!-- Theme & App -->
|
||||
<meta name="theme-color" content="#007AFF">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
|
||||
103
public/script.ts
103
public/script.ts
@@ -62,12 +62,115 @@ class QuixoticApp {
|
||||
private hasMoreResults: boolean = false;
|
||||
private isLoadingMore: boolean = false;
|
||||
private scrollObserver: IntersectionObserver | null = null;
|
||||
private currentVersion: string | null = null;
|
||||
|
||||
constructor() {
|
||||
this.tg = (window as WindowWithTelegram).Telegram?.WebApp;
|
||||
this.loadRecentSearches();
|
||||
this.init();
|
||||
this.bindEvents();
|
||||
this.checkVersion(); // Check for updates on load
|
||||
}
|
||||
|
||||
private async checkVersion(): Promise<void> {
|
||||
try {
|
||||
// Get current version from localStorage
|
||||
const storedVersion = localStorage.getItem('appVersion');
|
||||
|
||||
// Fetch latest version from server
|
||||
const response = await fetch('/api/version', {
|
||||
cache: 'no-cache',
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache',
|
||||
'Pragma': 'no-cache'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) return;
|
||||
|
||||
const versionData = await response.json();
|
||||
const serverVersion = versionData.version;
|
||||
|
||||
this.currentVersion = serverVersion;
|
||||
|
||||
// If versions don't match, force reload
|
||||
if (storedVersion && storedVersion !== serverVersion) {
|
||||
console.log('🔄 New version detected, updating...');
|
||||
|
||||
// Clear cache and reload
|
||||
if ('caches' in window) {
|
||||
const cacheNames = await caches.keys();
|
||||
await Promise.all(cacheNames.map(name => caches.delete(name)));
|
||||
}
|
||||
|
||||
// Store new version
|
||||
localStorage.setItem('appVersion', serverVersion);
|
||||
|
||||
// Force hard reload
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
// Store version for future checks
|
||||
if (!storedVersion) {
|
||||
localStorage.setItem('appVersion', serverVersion);
|
||||
}
|
||||
|
||||
// Periodically check for updates (every 5 minutes)
|
||||
setInterval(() => this.silentVersionCheck(), 5 * 60 * 1000);
|
||||
|
||||
} catch (error) {
|
||||
console.warn('Version check failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
private async silentVersionCheck(): Promise<void> {
|
||||
try {
|
||||
const response = await fetch('/api/version', {
|
||||
cache: 'no-cache',
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache',
|
||||
'Pragma': 'no-cache'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) return;
|
||||
|
||||
const versionData = await response.json();
|
||||
const serverVersion = versionData.version;
|
||||
|
||||
if (this.currentVersion && this.currentVersion !== serverVersion) {
|
||||
console.log('🔄 Update available');
|
||||
|
||||
// Show update notification
|
||||
this.showUpdateNotification();
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Silent version check failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
private showUpdateNotification(): void {
|
||||
const notification = document.createElement('div');
|
||||
notification.className = 'tg-update-notification';
|
||||
notification.innerHTML = `
|
||||
<div class="tg-update-notification__content">
|
||||
<span>Доступно обновление</span>
|
||||
<button class="tg-update-notification__button">Обновить</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const button = notification.querySelector('button');
|
||||
button?.addEventListener('click', () => {
|
||||
window.location.reload();
|
||||
});
|
||||
|
||||
document.body.appendChild(notification);
|
||||
|
||||
// Auto-dismiss after 30 seconds
|
||||
setTimeout(() => {
|
||||
notification.remove();
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
private triggerHaptic(type: 'light' | 'medium' | 'heavy' | 'success' | 'error' = 'light'): void {
|
||||
|
||||
@@ -696,6 +696,45 @@ body {
|
||||
}
|
||||
}
|
||||
|
||||
/* Update notification */
|
||||
.tg-update-notification {
|
||||
position: fixed;
|
||||
top: var(--tg-spacing-lg);
|
||||
left: var(--tg-spacing-lg);
|
||||
right: var(--tg-spacing-lg);
|
||||
z-index: 1000;
|
||||
animation: tg-slide-down 0.3s ease-out;
|
||||
}
|
||||
|
||||
.tg-update-notification__content {
|
||||
background: var(--tg-color-button);
|
||||
color: var(--tg-color-button-text);
|
||||
padding: var(--tg-spacing-md) var(--tg-spacing-lg);
|
||||
border-radius: var(--tg-border-radius);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
font-weight: var(--tg-font-weight-medium);
|
||||
}
|
||||
|
||||
.tg-update-notification__button {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
color: var(--tg-color-button-text);
|
||||
border: none;
|
||||
padding: var(--tg-spacing-sm) var(--tg-spacing-lg);
|
||||
border-radius: var(--tg-border-radius-small);
|
||||
font-size: var(--tg-font-size-sm);
|
||||
font-weight: var(--tg-font-weight-semibold);
|
||||
cursor: pointer;
|
||||
transition: background 0.2s ease;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
.tg-update-notification__button:active {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
/* Recent Searches */
|
||||
.tg-recent-searches {
|
||||
margin-bottom: var(--tg-spacing-lg);
|
||||
|
||||
Reference in New Issue
Block a user