feat:Strengthen the testing framework
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { logInfo as _ulogInfo, logError as _ulogError } from '@/lib/logging/core'
|
||||
import { buildFalQueueUrl } from '@/lib/providers/fal/base-url'
|
||||
/**
|
||||
* 异步任务提交工具
|
||||
*
|
||||
@@ -24,7 +25,7 @@ export async function submitFalTask(endpoint: string, input: Record<string, unkn
|
||||
throw new Error('请配置 FAL API Key')
|
||||
}
|
||||
|
||||
const response = await fetch(`https://queue.fal.run/${endpoint}`, {
|
||||
const response = await fetch(buildFalQueueUrl(endpoint), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -93,7 +94,7 @@ export async function queryFalStatus(endpoint: string, requestId: string, apiKey
|
||||
_ulogInfo(`[FAL Status] 解析端点 ${endpoint} -> ${baseEndpoint} (忽略路径: ${parsed.path})`)
|
||||
}
|
||||
|
||||
const statusUrl = `https://queue.fal.run/${baseEndpoint}/requests/${requestId}/status?logs=0`
|
||||
const statusUrl = buildFalQueueUrl(`${baseEndpoint}/requests/${requestId}/status?logs=0`)
|
||||
|
||||
// FAL 状态查询使用 GET 方法
|
||||
const response = await fetch(statusUrl, {
|
||||
@@ -122,7 +123,7 @@ export async function queryFalStatus(endpoint: string, requestId: string, apiKey
|
||||
// 优先使用返回的 response_url,如果没有则构建 URL
|
||||
// 注意:获取结果必须使用完整的原始端点(包括 /edit 等路径),而不是 baseEndpoint
|
||||
// 否则 FAL 会把请求当作新任务处理,导致 422 错误(缺少 image_urls 等必需参数)
|
||||
const resultUrl = data.response_url || `https://queue.fal.run/${endpoint}/requests/${requestId}`
|
||||
const resultUrl = data.response_url || buildFalQueueUrl(`${endpoint}/requests/${requestId}`)
|
||||
_ulogInfo(`[FAL Status] 任务已完成,获取结果: ${resultUrl}`)
|
||||
|
||||
const resultResponse = await fetch(resultUrl, {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
import { logInternal } from './logging/semantic'
|
||||
import { buildFalQueueUrl } from '@/lib/providers/fal/base-url'
|
||||
|
||||
export interface TaskStatus {
|
||||
status: 'pending' | 'completed' | 'failed'
|
||||
@@ -51,7 +52,7 @@ export async function queryBananaTaskStatus(requestId: string, apiKey: string):
|
||||
|
||||
try {
|
||||
const statusResponse = await fetch(
|
||||
`https://queue.fal.run/fal-ai/nano-banana-pro/requests/${requestId}/status`,
|
||||
buildFalQueueUrl(`fal-ai/nano-banana-pro/requests/${requestId}/status`),
|
||||
{
|
||||
headers: { 'Authorization': `Key ${apiKey}` },
|
||||
cache: 'no-store'
|
||||
@@ -68,7 +69,7 @@ export async function queryBananaTaskStatus(requestId: string, apiKey: string):
|
||||
if (data.status === 'COMPLETED') {
|
||||
// 获取结果
|
||||
const resultResponse = await fetch(
|
||||
`https://queue.fal.run/fal-ai/nano-banana-pro/requests/${requestId}`,
|
||||
buildFalQueueUrl(`fal-ai/nano-banana-pro/requests/${requestId}`),
|
||||
{
|
||||
headers: { 'Authorization': `Key ${apiKey}` },
|
||||
cache: 'no-store'
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
import { getProviderConfig } from '@/lib/api-config'
|
||||
import { submitFalTask } from '@/lib/async-submit'
|
||||
import { normalizeToBase64ForGeneration } from '@/lib/media/outbound-image'
|
||||
import { buildFalQueueUrl } from '@/lib/providers/fal/base-url'
|
||||
|
||||
// ============================================================
|
||||
// 图像模型端点映射(modelId → FAL 端点前缀)
|
||||
@@ -146,7 +147,7 @@ export class FalImageGenerator extends BaseImageGenerator {
|
||||
logger.info({
|
||||
message: 'FAL image request body summary',
|
||||
details: {
|
||||
url: `https://queue.fal.run/${endpoint}`,
|
||||
url: buildFalQueueUrl(endpoint),
|
||||
promptLength: prompt.length,
|
||||
imageUrlsCount: hasReferenceImages ? (body.image_urls as string[]).length : 0,
|
||||
resolution: body.resolution ?? null,
|
||||
@@ -156,7 +157,7 @@ export class FalImageGenerator extends BaseImageGenerator {
|
||||
})
|
||||
|
||||
// 提交异步任务
|
||||
const submitResponse = await fetch(`https://queue.fal.run/${endpoint}`, {
|
||||
const submitResponse = await fetch(buildFalQueueUrl(endpoint), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
16
src/lib/providers/fal/base-url.ts
Normal file
16
src/lib/providers/fal/base-url.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
const DEFAULT_FAL_QUEUE_BASE_URL = 'https://queue.fal.run'
|
||||
|
||||
function normalizeBaseUrl(value: string): string {
|
||||
return value.replace(/\/+$/, '')
|
||||
}
|
||||
|
||||
export function resolveFalQueueBaseUrl(): string {
|
||||
const override = process.env.FAL_QUEUE_BASE_URL?.trim()
|
||||
if (!override) return DEFAULT_FAL_QUEUE_BASE_URL
|
||||
return normalizeBaseUrl(override)
|
||||
}
|
||||
|
||||
export function buildFalQueueUrl(path: string): string {
|
||||
const normalizedPath = path.replace(/^\/+/, '')
|
||||
return `${resolveFalQueueBaseUrl()}/${normalizedPath}`
|
||||
}
|
||||
Reference in New Issue
Block a user