mirror of
https://github.com/open-webui/open-webui
synced 2024-11-16 13:40:55 +00:00
refac
This commit is contained in:
parent
86ee19178e
commit
efcb56f0dc
@ -175,6 +175,31 @@ def get_automatic1111_api_auth():
|
|||||||
return f"Basic {auth1111_base64_encoded_string}"
|
return f"Basic {auth1111_base64_encoded_string}"
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/config/url/verify")
|
||||||
|
async def verify_url(user=Depends(get_admin_user)):
|
||||||
|
if app.state.config.ENGINE == "automatic1111":
|
||||||
|
try:
|
||||||
|
r = requests.get(
|
||||||
|
url=f"{app.state.config.AUTOMATIC1111_BASE_URL}/sdapi/v1/options",
|
||||||
|
headers={"authorization": get_automatic1111_api_auth()},
|
||||||
|
)
|
||||||
|
r.raise_for_status()
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
app.state.config.ENABLED = False
|
||||||
|
raise HTTPException(status_code=400, detail=ERROR_MESSAGES.INVALID_URL)
|
||||||
|
elif app.state.config.ENGINE == "comfyui":
|
||||||
|
try:
|
||||||
|
r = requests.get(url=f"{app.state.config.COMFYUI_BASE_URL}/object_info")
|
||||||
|
r.raise_for_status()
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
app.state.config.ENABLED = False
|
||||||
|
raise HTTPException(status_code=400, detail=ERROR_MESSAGES.INVALID_URL)
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def set_image_model(model: str):
|
def set_image_model(model: str):
|
||||||
app.state.config.MODEL = model
|
app.state.config.MODEL = model
|
||||||
if app.state.config.ENGINE in ["", "automatic1111"]:
|
if app.state.config.ENGINE in ["", "automatic1111"]:
|
||||||
|
@ -67,6 +67,38 @@ export const updateConfig = async (token: string = '', config: object) => {
|
|||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const verifyConfigUrl = async (token: string = '') => {
|
||||||
|
let error = null;
|
||||||
|
|
||||||
|
const res = await fetch(`${IMAGES_API_BASE_URL}/config/url/verify`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...(token && { authorization: `Bearer ${token}` })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw await res.json();
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
if ('detail' in err) {
|
||||||
|
error = err.detail;
|
||||||
|
} else {
|
||||||
|
error = 'Server connection failed';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
export const getImageGenerationConfig = async (token: string = '') => {
|
export const getImageGenerationConfig = async (token: string = '') => {
|
||||||
let error = null;
|
let error = null;
|
||||||
|
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
getImageGenerationConfig,
|
getImageGenerationConfig,
|
||||||
updateImageGenerationConfig,
|
updateImageGenerationConfig,
|
||||||
getConfig,
|
getConfig,
|
||||||
updateConfig
|
updateConfig,
|
||||||
|
verifyConfigUrl
|
||||||
} from '$lib/apis/images';
|
} from '$lib/apis/images';
|
||||||
import SensitiveInput from '$lib/components/common/SensitiveInput.svelte';
|
import SensitiveInput from '$lib/components/common/SensitiveInput.svelte';
|
||||||
import Switch from '$lib/components/common/Switch.svelte';
|
import Switch from '$lib/components/common/Switch.svelte';
|
||||||
@ -255,8 +256,16 @@
|
|||||||
<button
|
<button
|
||||||
class="px-2.5 bg-gray-50 hover:bg-gray-100 text-gray-800 dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-gray-100 rounded-lg transition"
|
class="px-2.5 bg-gray-50 hover:bg-gray-100 text-gray-800 dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-gray-100 rounded-lg transition"
|
||||||
type="button"
|
type="button"
|
||||||
on:click={() => {
|
on:click={async () => {
|
||||||
updateConfigHandler();
|
await updateConfigHandler();
|
||||||
|
const res = await verifyConfigUrl(localStorage.token).catch((error) => {
|
||||||
|
toast.error(error);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
toast.success($i18n.t('Server connection verified'));
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
@ -323,8 +332,16 @@
|
|||||||
<button
|
<button
|
||||||
class="px-2.5 bg-gray-50 hover:bg-gray-100 text-gray-800 dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-gray-100 rounded-lg transition"
|
class="px-2.5 bg-gray-50 hover:bg-gray-100 text-gray-800 dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-gray-100 rounded-lg transition"
|
||||||
type="button"
|
type="button"
|
||||||
on:click={() => {
|
on:click={async () => {
|
||||||
updateConfigHandler();
|
await updateConfigHandler();
|
||||||
|
const res = await verifyConfigUrl(localStorage.token).catch((error) => {
|
||||||
|
toast.error(error);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
toast.success($i18n.t('Server connection verified'));
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
|
Loading…
Reference in New Issue
Block a user