fix: extension defaulting to UDP mode causing upload failures

The extension was saving and restoring UDP mode from storage. If UDP
was previously selected and the relay isn't configured, every upload
immediately fails with "UDP relay not configured".

- Default to HTTP mode on fresh installs (no saved mode)
- Before UDP upload, check /api/health relayConfigured flag and
  auto-fall-back to HTTP with a warning if relay isn't set up

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Zac Gaetano 2026-04-06 22:00:20 -04:00
parent 9e1e25ac97
commit b3f669afe4

View file

@ -14,6 +14,8 @@ let connected = false;
if (stored.config) config = { ...config, ...stored.config }; if (stored.config) config = { ...config, ...stored.config };
if (stored.token && stored.token !== null) authToken = stored.token; if (stored.token && stored.token !== null) authToken = stored.token;
if (stored.mode) uploadMode = stored.mode; if (stored.mode) uploadMode = stored.mode;
// Default to HTTP if no mode saved
if (!stored.mode) uploadMode = 'http';
document.getElementById('cfg-server').value = config.serverUrl; document.getElementById('cfg-server').value = config.serverUrl;
document.getElementById('cfg-user').value = config.username; document.getElementById('cfg-user').value = config.username;
@ -232,6 +234,17 @@ function updateBtn() {
// ==================== UPLOAD ==================== // ==================== UPLOAD ====================
async function startUpload() { async function startUpload() {
if (!connected) { showStatus('Not connected to server', 'error'); return; } if (!connected) { showStatus('Not connected to server', 'error'); return; }
// If UDP mode selected but relay not configured, fall back to HTTP silently
if (uploadMode === 'udp') {
try {
const health = await apiFetch('GET', '/api/health');
if (!health.relayConfigured) {
showStatus('⚠️ UDP relay not configured — switching to HTTP', 'loading');
setMode('http');
await new Promise(r => setTimeout(r, 1000));
}
} catch (_) {}
}
const pending = selectedFiles.filter(f => f.status === 'pending'); const pending = selectedFiles.filter(f => f.status === 'pending');
document.getElementById('upload-btn').disabled = true; document.getElementById('upload-btn').disabled = true;
const prefix = document.getElementById('folder-select').value; const prefix = document.getElementById('folder-select').value;