enh/refac: notes

This commit is contained in:
Timothy Jaeryang Baek
2025-12-09 16:45:08 -05:00
parent 1ea555a5ac
commit 9b24cddef6
5 changed files with 688 additions and 317 deletions
+55 -1
View File
@@ -91,6 +91,60 @@ export const getNotes = async (token: string = '', raw: boolean = false) => {
return grouped;
};
export const searchNotes = async (
token: string = '',
query: string | null = null,
viewOption: string | null = null,
sortKey: string | null = null,
page: number | null = null
) => {
let error = null;
const searchParams = new URLSearchParams();
if (query !== null) {
searchParams.append('query', query);
}
if (viewOption !== null) {
searchParams.append('view_option', viewOption);
}
if (sortKey !== null) {
searchParams.append('order_by', sortKey);
}
if (page !== null) {
searchParams.append('page', `${page}`);
}
const res = await fetch(`${WEBUI_API_BASE_URL}/notes/search?${searchParams.toString()}`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
authorization: `Bearer ${token}`
}
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.then((json) => {
return json;
})
.catch((err) => {
error = err.detail;
console.error(err);
return null;
});
if (error) {
throw error;
}
return res;
};
export const getNoteList = async (token: string = '', page: number | null = null) => {
let error = null;
const searchParams = new URLSearchParams();
@@ -99,7 +153,7 @@ export const getNoteList = async (token: string = '', page: number | null = null
searchParams.append('page', `${page}`);
}
const res = await fetch(`${WEBUI_API_BASE_URL}/notes/list?${searchParams.toString()}`, {
const res = await fetch(`${WEBUI_API_BASE_URL}/notes/?${searchParams.toString()}`, {
method: 'GET',
headers: {
Accept: 'application/json',