feat: move JSON model import to backend

This moves the JSON model import functionality to the backend. Instead of the frontend parsing the JSON file and sending multiple requests, it now uploads the file to a new endpoint (/api/v1/models/import), which processes the file and imports the models. This improves efficiency and provides better user feedback.
This commit is contained in:
silentoplayz
2025-09-28 18:09:58 -04:00
parent fe54fb61aa
commit 231d182c35
3 changed files with 103 additions and 33 deletions
+30
View File
@@ -31,6 +31,36 @@ export const getModels = async (token: string = '') => {
return res;
};
export const importModels = async (token: string, file: File) => {
let error = null;
const formData = new FormData();
formData.append('file', file);
const res = await fetch(`${WEBUI_API_BASE_URL}/models/import`, {
method: 'POST',
headers: {
authorization: `Bearer ${token}`
},
body: formData
})
.then(async (res) => {
if (!res.ok) throw await res.json();
return res.json();
})
.catch((err) => {
error = err;
console.error(err);
return null;
});
if (error) {
throw error;
}
return res;
};
export const getBaseModels = async (token: string = '') => {
let error = null;