feat: download db from admin settings

This commit is contained in:
Timothy J. Baek 2024-03-02 00:33:20 -08:00
parent 6d854125cc
commit edb63c2280
4 changed files with 144 additions and 1 deletions

View file

@ -21,3 +21,35 @@ export const getGravatarUrl = async (email: string) => {
return res;
};
export const downloadDatabase = async (token: string) => {
let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/utils/db/download`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`
}
})
.then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.blob();
})
.then((blob) => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'webui.db';
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
})
.catch((err) => {
console.log(err);
error = err;
return null;
});
};