This commit is contained in:
Timothy Jaeryang Baek
2026-09-18 19:28:40 -04:00
parent f3cf833e54
commit 64bbdf7a73
3 changed files with 51 additions and 42 deletions
+27 -31
View File
@@ -329,38 +329,34 @@ def get_automatic1111_api_auth(image_config):
return f'Basic {auth1111_base64_encoded_string}'
@router.get('/config/url/verify')
async def verify_url(request: Request, user=Depends(get_admin_user)):
image_config = await get_image_config()
if image_config.IMAGE_GENERATION_ENGINE == 'automatic1111':
try:
session = await get_session()
async with session.get(
url=f'{image_config.AUTOMATIC1111_BASE_URL}/sdapi/v1/options',
headers={'authorization': get_automatic1111_api_auth(image_config)},
ssl=AIOHTTP_CLIENT_SESSION_SSL,
) as r:
r.raise_for_status()
return True
except Exception:
raise HTTPException(status_code=400, detail=ERROR_MESSAGES.INVALID_URL)
elif image_config.IMAGE_GENERATION_ENGINE == 'comfyui':
headers = None
if image_config.COMFYUI_API_KEY:
headers = {'Authorization': f'Bearer {image_config.COMFYUI_API_KEY}'}
try:
session = await get_session()
async with session.get(
url=f'{image_config.COMFYUI_BASE_URL}/object_info',
headers=headers,
ssl=AIOHTTP_CLIENT_SESSION_SSL,
) as r:
r.raise_for_status()
return True
except Exception:
raise HTTPException(status_code=400, detail=ERROR_MESSAGES.INVALID_URL)
class ConnectionVerificationForm(BaseModel):
engine: str
url: str
key: str | None = None
@router.post('/verify')
async def verify_connection(form_data: ConnectionVerificationForm, user=Depends(get_admin_user)):
url = form_data.url.rstrip('/')
headers = {}
if form_data.engine == 'automatic1111':
url = f'{url}/sdapi/v1/options'
if form_data.key is not None:
headers['Authorization'] = f'Basic {base64.b64encode(form_data.key.encode("utf-8")).decode("utf-8")}'
elif form_data.engine == 'comfyui':
url = f'{url}/object_info'
if form_data.key:
headers['Authorization'] = f'Bearer {form_data.key}'
else:
return True
raise HTTPException(status_code=400, detail='Unsupported image engine')
try:
session = await get_session()
async with session.get(url=url, headers=headers, ssl=AIOHTTP_CLIENT_SESSION_SSL) as r:
r.raise_for_status()
return True
except Exception:
raise HTTPException(status_code=400, detail=ERROR_MESSAGES.INVALID_URL)
@router.get('/models')
+8 -4
View File
@@ -67,16 +67,20 @@ export const updateConfig = async (token: string = '', config: object) => {
return res;
};
export const verifyConfigUrl = async (token: string = '') => {
export const verifyConnection = async (
token: string = '',
connection: { engine: string; url: string; key?: string | null }
) => {
let error = null;
const res = await fetch(`${IMAGES_API_BASE_URL}/config/url/verify`, {
method: 'GET',
const res = await fetch(`${IMAGES_API_BASE_URL}/verify`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
...(token && { authorization: `Bearer ${token}` })
}
},
body: JSON.stringify(connection)
})
.then(async (res) => {
if (!res.ok) throw await res.json();
@@ -11,7 +11,7 @@
updateImageGenerationConfig,
getConfig,
updateConfig,
verifyConfigUrl
verifyConnection
} from '$lib/apis/images';
import Spinner from '$lib/components/common/Spinner.svelte';
import SensitiveInput from '$lib/components/common/SensitiveInput.svelte';
@@ -443,8 +443,11 @@
type="button"
aria-label={$i18n.t('settings.admin.images.verifyConnection.label')}
on:click={async () => {
await updateConfigHandler();
const res = await verifyConfigUrl(localStorage.token).catch((error) => {
const res = await verifyConnection(localStorage.token, {
engine: 'automatic1111',
url: config.AUTOMATIC1111_BASE_URL,
key: config.AUTOMATIC1111_API_AUTH
}).catch((error) => {
toast.error(`${error}`);
return null;
});
@@ -511,8 +514,11 @@
type="button"
aria-label={$i18n.t('settings.admin.images.verifyConnection.label')}
on:click={async () => {
await updateConfigHandler();
const res = await verifyConfigUrl(localStorage.token).catch((error) => {
const res = await verifyConnection(localStorage.token, {
engine: 'comfyui',
url: config.COMFYUI_BASE_URL,
key: config.COMFYUI_API_KEY
}).catch((error) => {
toast.error(`${error}`);
return null;
});
@@ -821,8 +827,11 @@
type="button"
aria-label={$i18n.t('settings.admin.images.verifyConnection.label')}
on:click={async () => {
await updateConfigHandler();
const res = await verifyConfigUrl(localStorage.token).catch((error) => {
const res = await verifyConnection(localStorage.token, {
engine: 'comfyui',
url: config.IMAGES_EDIT_COMFYUI_BASE_URL,
key: config.IMAGES_EDIT_COMFYUI_API_KEY
}).catch((error) => {
toast.error(`${error}`);
return null;
});