dev: new flag useComfyApi for auth [ci skip]

This commit is contained in:
bigcat88
2026-04-07 16:23:56 +03:00
parent 8527e16f74
commit 71cf071361
4 changed files with 22 additions and 23 deletions

View File

@@ -45,7 +45,8 @@ async function fetchItems() {
try {
const res = await fetchRemoteRoute(remoteConfig.value.route, {
params: remoteConfig.value.query_params,
timeout: remoteConfig.value.timeout ?? 30000
timeout: remoteConfig.value.timeout ?? 30000,
useComfyApi: remoteConfig.value.use_comfy_api
})
const data = remoteConfig.value.response_key
? res.data[remoteConfig.value.response_key]

View File

@@ -64,8 +64,8 @@ const fetchData = async (
) => {
const { route, response_key, query_params, timeout = TIMEOUT } = config
const url = resolveRoute(route)
const authHeaders = await getRemoteAuthHeaders(route)
const url = resolveRoute(route, config.use_comfy_api)
const authHeaders = await getRemoteAuthHeaders(config.use_comfy_api)
const res = await axios.get(url, {
params: query_params,

View File

@@ -3,21 +3,16 @@ import axios from 'axios'
import { getComfyApiBaseUrl } from '@/config/comfyApi'
import { useAuthStore } from '@/stores/authStore'
/**
* Check if a route is a comfy-api proxy route.
* These routes need the comfy-api base URL prepended and always require auth.
*/
function isProxyRoute(route: string): boolean {
return route.startsWith('/proxy/')
}
/**
* Resolve a RemoteOptions route to a full URL.
* - "/proxy/..." routes → prepend getComfyApiBaseUrl()
* - Everything else → use as-is
* - useComfyApi=true → prepend getComfyApiBaseUrl()
* - Otherwise → use as-is
*/
export function resolveRoute(route: string): string {
if (isProxyRoute(route)) {
export function resolveRoute(
route: string,
useComfyApi?: boolean
): string {
if (useComfyApi) {
return getComfyApiBaseUrl() + route
}
return route
@@ -25,13 +20,13 @@ export function resolveRoute(route: string): string {
/**
* Get auth headers for a remote request.
* - "/proxy/..." routes → ALWAYS inject auth (comfy-api requires it)
* - Other routes → only inject auth in cloud mode
* - useComfyApi=true → inject auth headers (comfy-api requires it)
* - Otherwise → no auth headers injected
*/
export async function getRemoteAuthHeaders(
route: string
useComfyApi?: boolean
): Promise<Record<string, any>> {
if (isProxyRoute(route)) {
if (useComfyApi) {
const authStore = useAuthStore()
const authHeader = await authStore.getAuthHeader()
if (authHeader) {
@@ -50,9 +45,11 @@ export async function fetchRemoteRoute(
params?: Record<string, string>
timeout?: number
signal?: AbortSignal
useComfyApi?: boolean
} = {}
) {
const url = resolveRoute(route)
const authHeaders = await getRemoteAuthHeaders(route)
return axios.get(url, { ...options, ...authHeaders })
const { useComfyApi, ...requestOptions } = options
const url = resolveRoute(route, useComfyApi)
const authHeaders = await getRemoteAuthHeaders(useComfyApi)
return axios.get(url, { ...requestOptions, ...authHeaders })
}

View File

@@ -24,7 +24,8 @@ const zRemoteWidgetConfig = z.object({
control_after_refresh: z.enum(['first', 'last']).optional(),
timeout: z.number().gte(0).optional(),
max_retries: z.number().gte(0).optional(),
item_schema: zRemoteItemSchema.optional()
item_schema: zRemoteItemSchema.optional(),
use_comfy_api: z.boolean().optional()
})
const zMultiSelectOption = z.object({
placeholder: z.string().optional(),