Fix double /api/ — remove prefix from paths, request function adds it
This commit is contained in:
+15
-15
@@ -12,30 +12,30 @@ async function request<T>(path: string, options?: RequestInit): Promise<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const api = {
|
export const api = {
|
||||||
getSettings: () => request<Settings>('/api/settings'),
|
getSettings: () => request<Settings>('/settings'),
|
||||||
updateSettings: (s: Partial<Settings>) =>
|
updateSettings: (s: Partial<Settings>) =>
|
||||||
request<Settings>('/api/settings', { method: 'POST', body: JSON.stringify(s) }),
|
request<Settings>('/settings', { method: 'POST', body: JSON.stringify(s) }),
|
||||||
getConversations: () => request<Conversation[]>('/api/conversations'),
|
getConversations: () => request<Conversation[]>('/conversations'),
|
||||||
newConversation: (title = 'New conversation') =>
|
newConversation: (title = 'New conversation') =>
|
||||||
request<Conversation>('/api/conversations', { method: 'POST', body: JSON.stringify({ title }) }),
|
request<Conversation>('/conversations', { method: 'POST', body: JSON.stringify({ title }) }),
|
||||||
getMessages: (id: string) => request<Message[]>(`/api/conversations/${id}/messages`),
|
getMessages: (id: string) => request<Message[]>(`/conversations/${id}/messages`),
|
||||||
renameConversation: (id: string, title: string) =>
|
renameConversation: (id: string, title: string) =>
|
||||||
request<Conversation>(`/api/conversations/${id}`, { method: 'PATCH', body: JSON.stringify({ title }) }),
|
request<Conversation>(`/conversations/${id}`, { method: 'PATCH', body: JSON.stringify({ title }) }),
|
||||||
deleteConversation: (id: string) =>
|
deleteConversation: (id: string) =>
|
||||||
request<{ deleted: string }>(`/api/conversations/${id}`, { method: 'DELETE' }),
|
request<{ deleted: string }>(`/conversations/${id}`, { method: 'DELETE' }),
|
||||||
clearAllConversations: () =>
|
clearAllConversations: () =>
|
||||||
request<{ cleared: boolean }>('/api/conversations', { method: 'DELETE' }),
|
request<{ cleared: boolean }>('/conversations', { method: 'DELETE' }),
|
||||||
sendMessage: (message: string, conversation_id: string) =>
|
sendMessage: (message: string, conversation_id: string) =>
|
||||||
request<ChatResponse>('/api/chat', { method: 'POST', body: JSON.stringify({ message, conversation_id }) }),
|
request<ChatResponse>('/chat', { method: 'POST', body: JSON.stringify({ message, conversation_id }) }),
|
||||||
getMemory: () => request<{ content: string }>('/api/memory'),
|
getMemory: () => request<{ content: string }>('/memory'),
|
||||||
updateMemory: (content: string) =>
|
updateMemory: (content: string) =>
|
||||||
request<{ saved: boolean }>('/api/memory', { method: 'POST', body: JSON.stringify({ content }) }),
|
request<{ saved: boolean }>('/memory', { method: 'POST', body: JSON.stringify({ content }) }),
|
||||||
getStatus: () => request<Status>('/api/status'),
|
getStatus: () => request<Status>('/status'),
|
||||||
reindex: () => request<{ started: boolean }>('/api/reindex', { method: 'POST' }),
|
reindex: () => request<{ started: boolean }>('/reindex', { method: 'POST' }),
|
||||||
transcribe: async (audio: Blob): Promise<{ text: string }> => {
|
transcribe: async (audio: Blob): Promise<{ text: string }> => {
|
||||||
const form = new FormData();
|
const form = new FormData();
|
||||||
form.append('audio', audio, 'recording.webm');
|
form.append('audio', audio, 'recording.webm');
|
||||||
const url = API_BASE ? `${API_BASE}/api/transcribe` : '/api/transcribe';
|
const url = '/api/transcribe';
|
||||||
const res = await fetch(url, { method: 'POST', credentials: 'include', body: form });
|
const res = await fetch(url, { method: 'POST', credentials: 'include', body: form });
|
||||||
if (!res.ok) throw new Error(`Transcribe error: ${res.status}`);
|
if (!res.ok) throw new Error(`Transcribe error: ${res.status}`);
|
||||||
return res.json();
|
return res.json();
|
||||||
@@ -46,7 +46,7 @@ export const api = {
|
|||||||
if (data.image) form.append('image', data.image);
|
if (data.image) form.append('image', data.image);
|
||||||
if (data.text) form.append('text', data.text);
|
if (data.text) form.append('text', data.text);
|
||||||
if (data.project) form.append('project', data.project);
|
if (data.project) form.append('project', data.project);
|
||||||
const url = API_BASE ? `${API_BASE}/api/capture` : '/api/capture';
|
const url = '/api/capture';
|
||||||
const res = await fetch(url, { method: 'POST', credentials: 'include', body: form });
|
const res = await fetch(url, { method: 'POST', credentials: 'include', body: form });
|
||||||
if (!res.ok) throw new Error(`Capture error: ${res.status}`);
|
if (!res.ok) throw new Error(`Capture error: ${res.status}`);
|
||||||
return res.json();
|
return res.json();
|
||||||
|
|||||||
Reference in New Issue
Block a user