mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-28 01:49:00 +09:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c4e946bb8 | ||
|
|
082d36a3c9 | ||
|
|
402eb9d86b |
No files matched your search
+1
-2
@@ -58,8 +58,7 @@ frontend/.eslintcache
|
||||
# Storybook
|
||||
frontend/storybook-static/
|
||||
|
||||
# PWA files
|
||||
frontend/**/public/sw.js
|
||||
# PWA auto-generated files (our sw.js is hand-written and should be tracked)
|
||||
frontend/**/public/workbox-*.js
|
||||
frontend/**/public/swe-worker-*.js
|
||||
|
||||
|
||||
@@ -105,11 +105,11 @@ EOF
|
||||
### GCE Encoding Worker
|
||||
```bash
|
||||
# SSH to restart service (clears in-memory job queue)
|
||||
gcloud compute ssh encoding-worker --zone=us-central1-a --project=nomadkaraoke \
|
||||
gcloud compute ssh encoding-worker --zone=us-central1-c --project=nomadkaraoke \
|
||||
--command="sudo systemctl restart encoding-worker"
|
||||
|
||||
# Check health
|
||||
gcloud compute ssh encoding-worker --zone=us-central1-a --project=nomadkaraoke \
|
||||
gcloud compute ssh encoding-worker --zone=us-central1-c --project=nomadkaraoke \
|
||||
--command="curl -s http://localhost:8080/health"
|
||||
```
|
||||
|
||||
|
||||
@@ -148,6 +148,9 @@ Use `pulumi up --skip-preview --yes` when CI service account can't run preview.
|
||||
### Docker Disk Management
|
||||
Self-hosted runners need aggressive disk cleanup. Use threshold-based (70%) not age-based cleanup.
|
||||
|
||||
### Version Sort for Artifact Selection
|
||||
When downloading multiple versioned files (wheels, tarballs), use `sort -V | tail -1` not `ls -t | head -1`. Files downloaded simultaneously have the same timestamp, so time-based sorting picks arbitrarily. Version sorting (`sort -V`) correctly identifies the highest semantic version.
|
||||
|
||||
---
|
||||
|
||||
## Performance Patterns
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
/**
|
||||
* Service Worker for Web Push Notifications
|
||||
*
|
||||
* Handles push events and notification clicks for the Karaoke Generator PWA.
|
||||
* This service worker is registered by the ServiceWorkerRegistration component.
|
||||
*/
|
||||
|
||||
// Cache name for static assets (versioned for updates)
|
||||
const CACHE_VERSION = 'v1';
|
||||
const STATIC_CACHE = `karaoke-gen-static-${CACHE_VERSION}`;
|
||||
|
||||
// Assets to cache for offline support
|
||||
const STATIC_ASSETS = [
|
||||
'/nomad-logo.png',
|
||||
'/nomad-karaoke-logo.svg',
|
||||
'/favicon.ico',
|
||||
];
|
||||
|
||||
/**
|
||||
* Install event - cache static assets
|
||||
*/
|
||||
self.addEventListener('install', (event) => {
|
||||
console.log('[SW] Installing service worker...');
|
||||
event.waitUntil(
|
||||
caches.open(STATIC_CACHE).then((cache) => {
|
||||
return cache.addAll(STATIC_ASSETS);
|
||||
}).then(() => {
|
||||
console.log('[SW] Static assets cached');
|
||||
return self.skipWaiting(); // Activate immediately
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Activate event - clean up old caches
|
||||
*/
|
||||
self.addEventListener('activate', (event) => {
|
||||
console.log('[SW] Activating service worker...');
|
||||
event.waitUntil(
|
||||
caches.keys().then((cacheNames) => {
|
||||
return Promise.all(
|
||||
cacheNames
|
||||
.filter((name) => name.startsWith('karaoke-gen-') && name !== STATIC_CACHE)
|
||||
.map((name) => {
|
||||
console.log('[SW] Deleting old cache:', name);
|
||||
return caches.delete(name);
|
||||
})
|
||||
);
|
||||
}).then(() => {
|
||||
console.log('[SW] Service worker activated');
|
||||
return self.clients.claim(); // Take control of all pages
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Push event - show notification when push message received
|
||||
*/
|
||||
self.addEventListener('push', (event) => {
|
||||
console.log('[SW] Push event received');
|
||||
|
||||
let data = {
|
||||
title: 'Karaoke Generator',
|
||||
body: 'You have a notification',
|
||||
icon: '/nomad-logo.png',
|
||||
tag: 'default',
|
||||
url: '/app/',
|
||||
};
|
||||
|
||||
// Parse push data if available
|
||||
if (event.data) {
|
||||
try {
|
||||
const payload = event.data.json();
|
||||
data = {
|
||||
title: payload.title || data.title,
|
||||
body: payload.body || data.body,
|
||||
icon: payload.icon || data.icon,
|
||||
tag: payload.tag || data.tag,
|
||||
url: payload.url || data.url,
|
||||
};
|
||||
} catch (err) {
|
||||
console.error('[SW] Error parsing push data:', err);
|
||||
// Try as text
|
||||
const text = event.data.text();
|
||||
if (text) {
|
||||
data.body = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Show the notification
|
||||
const options = {
|
||||
body: data.body,
|
||||
icon: data.icon,
|
||||
badge: '/favicon-32x32.png',
|
||||
tag: data.tag, // Replaces notifications with same tag
|
||||
renotify: true, // Vibrate/sound even if replacing
|
||||
requireInteraction: true, // Don't auto-dismiss
|
||||
data: {
|
||||
url: data.url,
|
||||
},
|
||||
// Actions for the notification (optional)
|
||||
actions: [
|
||||
{
|
||||
action: 'open',
|
||||
title: 'Open',
|
||||
},
|
||||
{
|
||||
action: 'dismiss',
|
||||
title: 'Dismiss',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
event.waitUntil(
|
||||
self.registration.showNotification(data.title, options)
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Notification click event - open the app or focus existing window
|
||||
*/
|
||||
self.addEventListener('notificationclick', (event) => {
|
||||
console.log('[SW] Notification clicked:', event.action);
|
||||
|
||||
event.notification.close();
|
||||
|
||||
// Handle dismiss action
|
||||
if (event.action === 'dismiss') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the URL to open
|
||||
const url = event.notification.data?.url || '/app/';
|
||||
const fullUrl = new URL(url, self.location.origin).href;
|
||||
|
||||
// Try to focus an existing window or open a new one
|
||||
event.waitUntil(
|
||||
self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clients) => {
|
||||
// Check if there's already a window open
|
||||
for (const client of clients) {
|
||||
// If we find a matching URL, focus it
|
||||
if (client.url === fullUrl && 'focus' in client) {
|
||||
return client.focus();
|
||||
}
|
||||
}
|
||||
|
||||
// Check if there's any window from our origin
|
||||
for (const client of clients) {
|
||||
if (client.url.startsWith(self.location.origin) && 'focus' in client) {
|
||||
// Navigate the existing window and focus it
|
||||
return client.navigate(fullUrl).then((client) => client?.focus());
|
||||
}
|
||||
}
|
||||
|
||||
// No existing window, open a new one
|
||||
if (self.clients.openWindow) {
|
||||
return self.clients.openWindow(fullUrl);
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Notification close event - cleanup if needed
|
||||
*/
|
||||
self.addEventListener('notificationclose', (event) => {
|
||||
console.log('[SW] Notification closed');
|
||||
// Could track analytics here if desired
|
||||
});
|
||||
|
||||
/**
|
||||
* Message event - handle messages from the main app
|
||||
*/
|
||||
self.addEventListener('message', (event) => {
|
||||
console.log('[SW] Message received:', event.data);
|
||||
|
||||
if (event.data?.type === 'SKIP_WAITING') {
|
||||
self.skipWaiting();
|
||||
}
|
||||
});
|
||||
|
||||
console.log('[SW] Service worker loaded');
|
||||
@@ -182,7 +182,7 @@ High-performance VM for video encoding:
|
||||
|
||||
**Troubleshooting:**
|
||||
```bash
|
||||
gcloud compute ssh encoding-worker --zone=us-central1-a -- \
|
||||
gcloud compute ssh encoding-worker --zone=us-central1-c -- \
|
||||
"sudo systemctl status encoding-worker"
|
||||
```
|
||||
|
||||
|
||||
@@ -118,7 +118,9 @@ echo "ENCODING_API_KEY=${ENCODING_API_KEY}" > /opt/encoding-worker/env
|
||||
# This enables hot code updates without rebuilding the image
|
||||
echo "Installing latest karaoke-gen wheel from GCS..."
|
||||
gsutil cp "gs://karaoke-gen-storage-nomadkaraoke/wheels/karaoke_gen-*.whl" /tmp/ 2>/dev/null || true
|
||||
WHEEL_FILE=$(ls -t /tmp/karaoke_gen-*.whl 2>/dev/null | head -1)
|
||||
# Use version sort (-V) to get the highest version, not time sort (-t)
|
||||
# All wheels download at the same time, so -t picks arbitrarily
|
||||
WHEEL_FILE=$(ls /tmp/karaoke_gen-*.whl 2>/dev/null | sort -V | tail -1)
|
||||
if [ -n "$WHEEL_FILE" ]; then
|
||||
echo "Installing wheel: $WHEEL_FILE"
|
||||
/opt/encoding-worker/venv/bin/pip install --upgrade --quiet "$WHEEL_FILE" || echo "WARNING: Failed to install wheel"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "karaoke-gen"
|
||||
version = "0.105.0"
|
||||
version = "0.105.1"
|
||||
description = "Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video with title screens."
|
||||
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
|
||||
license = "MIT"
|
||||
|
||||
Reference in new issue
Block a user