DragonWind/chrome-extension/background.js
Zac Gaetano 641701edf8 feat: Dragon Wind v1.0 — dual-mode broadcast uploader
- Full VPM Uploader feature set (auth, users, folders, AMPP monitor)
- HTTP upload via presigned S3 URLs with XHR progress tracking
- UDP upload mode with relay server (WebRTC DataChannel + HTTP fallback)
- S3 Admin settings with live Test Connection (upload+delete verify)
- UDP Relay Admin settings with health check
- Standalone UDP relay server (Node.js + Docker) with multipart S3 assembly
- Chrome Extension (Manifest v3): popup, background, content script
- Dynamic S3 client — reconfigures on save without restart
- Dark/light theme, full AMPP job monitor
- docker-compose.yml with dragon-wind + udp-relay services

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-05 20:05:34 -04:00

41 lines
1.3 KiB
JavaScript

"use strict";
/**
* Dragon Wind — Background Service Worker
* Handles badge updates and keeps auth token alive.
*/
chrome.runtime.onInstalled.addListener(() => {
chrome.action.setBadgeBackgroundColor({ color: '#e05c1a' });
console.log('[Dragon Wind] Extension installed');
});
// Listen for messages from popup/content scripts
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
if (msg.type === 'SET_BADGE') {
chrome.action.setBadgeText({ text: msg.text || '' });
sendResponse({ ok: true });
}
if (msg.type === 'UPLOAD_COMPLETE') {
chrome.action.setBadgeText({ text: '✓' });
setTimeout(() => chrome.action.setBadgeText({ text: '' }), 3000);
sendResponse({ ok: true });
}
return true;
});
// Periodic health check (every 5 min)
chrome.alarms.create('health-check', { periodInMinutes: 5 });
chrome.alarms.onAlarm.addListener(async (alarm) => {
if (alarm.name !== 'health-check') return;
const stored = await chrome.storage.local.get(['config', 'token']);
if (!stored.config?.serverUrl || !stored.token) return;
try {
const r = await fetch(`${stored.config.serverUrl}/api/health`, {
headers: { 'x-auth-token': stored.token }
});
if (r.status === 401) {
await chrome.storage.local.remove('token');
console.log('[Dragon Wind] Token expired — cleared');
}
} catch (_) {}
});