From 797ed9ac7f5590bd0358e55f632ec5f729873d21 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 21 Feb 2024 18:57:53 -0800 Subject: [PATCH] feat: allow enabling after url is provided --- backend/apps/images/main.py | 8 ++++++-- src/lib/components/chat/Settings/Images.svelte | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/apps/images/main.py b/backend/apps/images/main.py index 4539f8066..4521706dd 100644 --- a/backend/apps/images/main.py +++ b/backend/apps/images/main.py @@ -43,8 +43,12 @@ async def get_enable_status(request: Request, user=Depends(get_admin_user)): @app.get("/enabled/toggle", response_model=bool) async def toggle_enabled(request: Request, user=Depends(get_admin_user)): - app.state.ENABLED = not app.state.ENABLED - return app.state.ENABLED + try: + r = requests.head(app.state.AUTOMATIC1111_BASE_URL) + app.state.ENABLED = not app.state.ENABLED + return app.state.ENABLED + except Exception as e: + raise HTTPException(status_code=r.status_code, detail=ERROR_MESSAGES.DEFAULT(e)) class UrlUpdateForm(BaseModel): diff --git a/src/lib/components/chat/Settings/Images.svelte b/src/lib/components/chat/Settings/Images.svelte index d09d12e33..5cea4c8fa 100644 --- a/src/lib/components/chat/Settings/Images.svelte +++ b/src/lib/components/chat/Settings/Images.svelte @@ -45,8 +45,13 @@ }; const toggleImageGeneration = async () => { - enableImageGeneration = await toggleImageGenerationEnabledStatus(localStorage.token); - config.set(await getBackendConfig(localStorage.token)); + if (AUTOMATIC1111_BASE_URL) { + enableImageGeneration = await toggleImageGenerationEnabledStatus(localStorage.token); + config.set(await getBackendConfig(localStorage.token)); + } else { + enableImageGeneration = false; + toast.error('AUTOMATIC1111_BASE_URL not provided'); + } }; onMount(async () => {