refac
This commit is contained in:
1 parent
223f484ded
commit
7e8153e889
3 files changed
+313
-7
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
|
||||
import type { Banner } from '$lib/types';
|
||||
|
||||
export const importConfig = async (token: string, config) => {
|
||||
export const importConfig = async (token: string, config: object) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/import`, {
|
||||
@@ -275,7 +275,8 @@ export const putOrchestratorPolicy = async (
|
||||
url: string,
|
||||
key: string,
|
||||
policyId: string,
|
||||
policyData: object
|
||||
policyData: object,
|
||||
authType: string = 'bearer'
|
||||
): Promise<object | null> => {
|
||||
let error = null;
|
||||
|
||||
@@ -288,6 +289,7 @@ export const putOrchestratorPolicy = async (
|
||||
body: JSON.stringify({
|
||||
url: url.replace(/\/$/, ''),
|
||||
key,
|
||||
auth_type: authType,
|
||||
policy_id: policyId,
|
||||
policy_data: policyData
|
||||
})
|
||||
@@ -309,6 +311,91 @@ export const putOrchestratorPolicy = async (
|
||||
return res;
|
||||
};
|
||||
|
||||
export const putOrchestratorLifecycle = async (
|
||||
token: string,
|
||||
url: string,
|
||||
key: string,
|
||||
policyId: string,
|
||||
lifecycleData: object,
|
||||
authType: string = 'bearer'
|
||||
): Promise<object | null> => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/terminal_servers/lifecycle`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
url: url.replace(/\/$/, ''),
|
||||
key,
|
||||
auth_type: authType,
|
||||
policy_id: policyId,
|
||||
lifecycle_data: lifecycleData
|
||||
})
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
error = err.detail;
|
||||
return null;
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
export const refreshOrchestratorTerminals = async (
|
||||
token: string,
|
||||
url: string,
|
||||
key: string,
|
||||
body: {
|
||||
user_id?: string;
|
||||
policy_id?: string;
|
||||
only_idle?: boolean;
|
||||
reset?: boolean;
|
||||
},
|
||||
authType: string = 'bearer'
|
||||
): Promise<object | null> => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/terminal_servers/refresh`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
url: url.replace(/\/$/, ''),
|
||||
key,
|
||||
auth_type: authType,
|
||||
...body
|
||||
})
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
error = err.detail;
|
||||
return null;
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
/**
|
||||
* Verify a terminal server connection via the backend proxy.
|
||||
* Used for system/admin connections to avoid CORS issues and API key exposure.
|
||||
|
||||
Reference in new issue
Block a user