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 () => {