diff --git a/Plugin/unraid/pages/ai.php b/Plugin/unraid/pages/ai.php index b37c00c..27b11a7 100644 --- a/Plugin/unraid/pages/ai.php +++ b/Plugin/unraid/pages/ai.php @@ -436,15 +436,26 @@ if (is_dir('/var/log/varaverk')) { // installed elsewhere on the page — would escape the promise chain entirely and leave the // pending indicator up forever with nothing logged anywhere. A hang is the one failure // that tells you nothing, so every path below has to end in a visible message. + // URLSearchParams, not FormData. FormData sends multipart/form-data, and a multipart POST + // to this endpoint hangs with no status code ever returned — the request leaves the browser + // with a valid token and correct body, and never reaches PHP: no CSRF termination, no + // fatal, no entry log. Every other POST on this host that demonstrably works, including + // Unraid's own, is application/x-www-form-urlencoded. Same fields, same $_POST on the + // server; only the encoding changes. let res; try { - const fd = new FormData(); - fd.append('action', 'ask'); - fd.append('question', q); - fd.append('history', JSON.stringify(history.slice(-MAXTURN * 2))); - fd.append('kind', $('vv-ai-kind').value); - fd.append('think', $('vv-ai-think').checked ? '1' : '0'); - res = fetch(API, { method: 'POST', body: fd }); + const body = new URLSearchParams({ + action: 'ask', + question: q, + history: JSON.stringify(history.slice(-MAXTURN * 2)), + kind: $('vv-ai-kind').value, + think: $('vv-ai-think').checked ? '1' : '0', + }); + res = fetch(API, { + method: 'POST', + headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, + body, + }); } catch (e) { addError('Could not send the request: ' + (e && e.message ? e.message : e) + ' — this failed in the browser before reaching the server.'); @@ -489,8 +500,9 @@ if (is_dir('/var/log/varaverk')) { addAnswer(j); history.push({ role: 'assistant', content: j.answer }); if (history.length > MAXTURN * 2) history = history.slice(-MAXTURN * 2); - const fd = new FormData(); fd.append('action','clear'); fd.append('token',token); - fetch(API, { method:'POST', body: fd }).catch(() => {}); + fetch(API, { method: 'POST', + headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, + body: new URLSearchParams({ action: 'clear', token }) }).catch(() => {}); finish(); loadBanner(); return; } if (j.status === 'error') { addError(j.error || 'Unknown error'); finish(); return; }