mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-03 13:19:16 +00:00
Pass query params to chat API in POST body instead of URL query string
Closes #899, #678
This commit is contained in:
@@ -103,7 +103,7 @@
|
||||
let conversationID = chatBody.dataset.conversationId;
|
||||
let hostURL = await window.hostURLAPI.getURL();
|
||||
const khojToken = await window.tokenAPI.getToken();
|
||||
const headers = { 'Authorization': `Bearer ${khojToken}` };
|
||||
const headers = { 'Authorization': `Bearer ${khojToken}`, 'Content-Type': 'application/json' };
|
||||
|
||||
if (!conversationID) {
|
||||
let response = await fetch(`${hostURL}/api/chat/sessions`, { method: "POST", headers });
|
||||
@@ -149,12 +149,22 @@
|
||||
document.getElementById("send-button").style.display = "none";
|
||||
|
||||
// Call Khoj chat API
|
||||
let chatApi = `${hostURL}/api/chat?q=${encodeURIComponent(query)}&conversation_id=${conversationID}&stream=true&client=desktop`;
|
||||
chatApi += (!!region && !!city && !!countryName && !!timezone)
|
||||
? `®ion=${region}&city=${city}&country=${countryName}&timezone=${timezone}`
|
||||
: '';
|
||||
const chatApi = `${hostURL}/api/chat?client=desktop`;
|
||||
const chatApiBody = {
|
||||
q: query,
|
||||
conversation_id: parseInt(conversationID),
|
||||
stream: true,
|
||||
...(!!city && { city: city }),
|
||||
...(!!region && { region: region }),
|
||||
...(!!countryName && { country: countryName }),
|
||||
...(!!timezone && { timezone: timezone }),
|
||||
};
|
||||
|
||||
const response = await fetch(chatApi, { method: 'POST', headers });
|
||||
const response = await fetch(chatApi, {
|
||||
method: "POST",
|
||||
headers: headers,
|
||||
body: JSON.stringify(chatApiBody),
|
||||
});
|
||||
|
||||
try {
|
||||
if (!response.ok) throw new Error(response.statusText);
|
||||
|
||||
Reference in New Issue
Block a user