2024-06-20 07:49:11 +00:00
|
|
|
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
|
|
|
|
|
|
|
export const createNewFunction = async (token: string, func: object) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/functions/create`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
...func
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err.detail;
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getFunctions = async (token: string = '') => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/functions/`, {
|
|
|
|
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.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const exportFunctions = async (token: string = '') => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/functions/export`, {
|
|
|
|
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.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getFunctionById = async (token: string, id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/functions/id/${id}`, {
|
|
|
|
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.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const updateFunctionById = async (token: string, id: string, func: object) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/functions/id/${id}/update`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
...func
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err.detail;
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteFunctionById = async (token: string, id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/functions/id/${id}/delete`, {
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
2024-06-24 01:34:42 +00:00
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err.detail;
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const toggleFunctionById = async (token: string, id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/functions/id/${id}/toggle`, {
|
|
|
|
method: 'POST',
|
2024-06-27 20:04:12 +00:00
|
|
|
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.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const toggleGlobalById = async (token: string, id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/functions/id/${id}/toggle/global`, {
|
|
|
|
method: 'POST',
|
2024-06-24 01:34:42 +00:00
|
|
|
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.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getFunctionValvesById = async (token: string, id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/functions/id/${id}/valves`, {
|
|
|
|
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.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
2024-06-24 02:02:27 +00:00
|
|
|
export const getFunctionValvesSpecById = async (token: string, id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/functions/id/${id}/valves/spec`, {
|
|
|
|
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.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
2024-06-24 01:34:42 +00:00
|
|
|
export const updateFunctionValvesById = async (token: string, id: string, valves: object) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/functions/id/${id}/valves/update`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
...valves
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
2024-06-20 07:49:11 +00:00
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err.detail;
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
2024-06-22 19:08:32 +00:00
|
|
|
|
|
|
|
export const getUserValvesById = async (token: string, id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/functions/id/${id}/valves/user`, {
|
|
|
|
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.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getUserValvesSpecById = async (token: string, id: string) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/functions/id/${id}/valves/user/spec`, {
|
|
|
|
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.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const updateUserValvesById = async (token: string, id: string, valves: object) => {
|
|
|
|
let error = null;
|
|
|
|
|
|
|
|
const res = await fetch(`${WEBUI_API_BASE_URL}/functions/id/${id}/valves/user/update`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
authorization: `Bearer ${token}`
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
...valves
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(async (res) => {
|
|
|
|
if (!res.ok) throw await res.json();
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
|
|
|
return json;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
error = err.detail;
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
};
|