Send AI POSTs urlencoded instead of multipart
A multipart POST to this endpoint hangs: no status code is ever returned, and the request never reaches PHP — no CSRF termination, no fatal, no entry log — despite leaving the browser with a valid token and a correct body. Every POST on this host that demonstrably works, including Unraid's own, is x-www-form-urlencoded. Same fields and same $_POST server-side.
This commit is contained in:
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user