diff --git a/app/(chat)/gallery/page.tsx b/app/(chat)/gallery/page.tsx index fb67d2507..2c41a850f 100644 --- a/app/(chat)/gallery/page.tsx +++ b/app/(chat)/gallery/page.tsx @@ -143,57 +143,28 @@ export default function GalleryPage() { try { toast.info("正在处理抠图,请稍候..."); - // 获取原图并转换为Base64 - const response = await fetch(image.url); - const blob = await response.blob(); - const reader = new FileReader(); - - reader.onloadend = async () => { - try { - const base64Data = (reader.result as string).split(",")[1]; - - // 调用抠图API - const rmbgResponse = await fetch("/api/rmbg", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - image_base64: base64Data, - prompt: `抠图处理 - ${image.alt}`, - chatId: image.chatId, - messageId: image.messageId, - }), - }); - - if (!rmbgResponse.ok) { - const error = await rmbgResponse.json(); - throw new Error(error.error || error.detail || "抠图失败"); - } - - const result = await rmbgResponse.json(); - - // 刷新相册列表以显示新图片 - await fetchImages(pagination.page); - - toast.success(`抠图完成!处理时间: ${result.processing_time?.toFixed(2) || "未知"}秒`); - } catch (error) { - console.error("[抠图] 错误:", error); - toast.error(error instanceof Error ? error.message : "抠图处理失败"); - } finally { - setProcessingImageId(null); - } - }; - - reader.onerror = () => { - toast.error("图片读取失败"); - setProcessingImageId(null); - }; - - reader.readAsDataURL(blob); + const imageUrl = new URL(image.url, window.location.origin).href; + const response = await fetch("/api/rmbg", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + imageUrl, + prompt: `抠图处理 - ${image.alt}`, + chatId: image.chatId, + messageId: image.messageId, + includeBase64: false, + }), + }); + const result = await response.json(); + if (!response.ok || !result.success) { + throw new Error(result.error || result.detail || "抠图失败"); + } + await fetchImages(pagination.page); + toast.success(`抠图完成!处理时间: ${result.processing_time?.toFixed(2) || "未知"}秒`); } catch (error) { console.error("[抠图] 错误:", error); toast.error(error instanceof Error ? error.message : "抠图处理失败"); + } finally { setProcessingImageId(null); } }; @@ -208,51 +179,23 @@ export default function GalleryPage() { try { toast.info("正在处理图片变清晰,请稍候..."); - // 获取原图并转换为Base64 - const response = await fetch(image.url); - const blob = await response.blob(); - const reader = new FileReader(); - - reader.onloadend = async () => { - try { - const base64Data = (reader.result as string).split(",")[1]; - - const result = await requestLongTaskResult({ - endpoint: "/api/enhance", - payload: { - image_base64: base64Data, - prompt: `图片变清晰处理 - ${image.alt}`, - chatId: image.chatId, - messageId: image.messageId, - }, - pollingParams: { - prompt: `图片变清晰处理 - ${image.alt}`, - chatId: image.chatId, - messageId: image.messageId, - }, - }); - - // 刷新相册列表以显示新图片 - await fetchImages(pagination.page); - - toast.success(`变清晰完成!处理时间: ${result.processing_time?.toFixed(2) || "未知"}秒`); - } catch (error) { - console.error("[变清晰] 错误:", error); - toast.error(error instanceof Error ? error.message : "变清晰处理失败"); - } finally { - setEnhancingImageId(null); - } - }; - - reader.onerror = () => { - toast.error("图片读取失败"); - setEnhancingImageId(null); - }; - - reader.readAsDataURL(blob); + const imageUrl = new URL(image.url, window.location.origin).href; + const prompt = `图片变清晰处理 - ${image.alt}`; + const { chatId, messageId } = image; + const result = await requestLongTaskResult({ + endpoint: "/api/enhance", + payload: { imageUrl, prompt, chatId, messageId, includeBase64: false }, + pollingParams: { sourceImageUrl: imageUrl, prompt, chatId, messageId, includeBase64: "false" }, + }); + if (!result?.success) { + throw new Error(result?.error || result?.detail || "变清晰处理失败"); + } + await fetchImages(pagination.page); + toast.success(`变清晰完成!处理时间: ${result.processing_time?.toFixed(2) || "未知"}秒`); } catch (error) { console.error("[变清晰] 错误:", error); toast.error(error instanceof Error ? error.message : "变清晰处理失败"); + } finally { setEnhancingImageId(null); } }; diff --git a/app/api/agent-workflow/material-upload/route.ts b/app/api/agent-workflow/material-upload/route.ts index ebd4265ee..80bdec0cd 100644 --- a/app/api/agent-workflow/material-upload/route.ts +++ b/app/api/agent-workflow/material-upload/route.ts @@ -110,6 +110,7 @@ export async function POST(request: NextRequest) { const result = await executeRmbgJob({ userId: session.user.id, imageBuffer, + includeBase64: false, prompt, skipGallerySave: true, }); diff --git a/app/api/resize/route.ts b/app/api/resize/route.ts index dfb0aaac1..765aaaf42 100644 --- a/app/api/resize/route.ts +++ b/app/api/resize/route.ts @@ -45,6 +45,7 @@ export async function POST(request: NextRequest) { return NextResponse.json({ success: true, ...result, + image_base64: body.includeBase64 === false ? undefined : result.image_base64, }); } catch (error) { if (error instanceof ResizeServiceError) { diff --git a/components/angle-edit-dialog.tsx b/components/angle-edit-dialog.tsx index ef2649704..91040329b 100644 --- a/components/angle-edit-dialog.tsx +++ b/components/angle-edit-dialog.tsx @@ -107,6 +107,7 @@ export function AngleEditDialog({ headers: { "Content-Type": "application/json" }, body: JSON.stringify({ image_url: imageUrl, + includeBase64: false, horizontal_angle: cameraState.azimuth, // 0-360 度 vertical_angle: cameraState.elevation, // -30 到 90 度 zoom: cameraState.distance, // 0-10 diff --git a/components/image-annotator.tsx b/components/image-annotator.tsx index 4088ab926..97485bd74 100644 --- a/components/image-annotator.tsx +++ b/components/image-annotator.tsx @@ -885,87 +885,48 @@ export function ImageAnnotator({ setActions([]); }; - // 将图片URL转换为Base64(获取原图数据) - const imageUrlToBase64 = async (url: string): Promise => { - // 如果已经是data URL,直接返回 - if (url.startsWith("data:")) { - return url.split(",")[1]; + const resolveProcessingImageUrl = async (url: string): Promise => { + const source = new URL(url, window.location.origin); + if (source.protocol === "https:" || source.protocol === "http:") { + return source.href; } - // 如果是HTTP URL,需要先fetch获取 - const response = await fetch(url); - if (!response.ok) { - throw new Error( - `获取原图失败: ${response.status} ${response.statusText}` - ); - } + const response = await fetch(source.href); + if (!response.ok) throw new Error("无法读取待处理图片"); const blob = await response.blob(); - - return new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.onloadend = () => { - const base64String = (reader.result as string).split(",")[1]; - resolve(base64String); - }; - reader.onerror = reject; - reader.readAsDataURL(blob); - }); + const extension = blob.type === "image/jpeg" ? "jpg" : blob.type.split("/")[1] || "png"; + const file = new File([blob], `source-${Date.now()}.${extension}`, { type: blob.type }); + return (await uploadImageFile(file)).url; }; - // 抠图功能 const handleRemoveBackground = async () => { if (!image || !originalImageUrl) return; setIsRemovingBg(true); try { - const input = /^https?:\/\//i.test(originalImageUrl) - ? { imageUrl: originalImageUrl } - : { image_base64: await imageUrlToBase64(originalImageUrl) }; - - // 调用抠图API + const imageUrl = await resolveProcessingImageUrl(originalImageUrl); const response = await fetch("/api/rmbg", { method: "POST", - headers: { - "Content-Type": "application/json", - }, + headers: { "Content-Type": "application/json" }, body: JSON.stringify({ - ...input, - prompt: "画图标注-抠图处理", // 可选:添加提示词 + imageUrl, + prompt: "画图标注-抠图处理", + includeBase64: false, }), }); - if (!response.ok) { - const error = await response.json(); - throw new Error(error.error || "抠图失败"); - } - const result = await response.json(); - - if (result.success && result.image_base64) { - // 保存处理后的图片URL和Base64(优先使用original_url,确保下载的是原图) - logger.info("rmbg_completed", { - hasOriginalUrl: !!result.original_url, - hasThumbnailUrl: !!result.thumbnail_url, - base64Length: String(result.image_base64 || "").length, - }); - if (result.original_url) { - setProcessedImageUrl(result.original_url); - } else if (result.thumbnail_url) { - logger.warn("rmbg_original_url_missing", { hasThumbnailUrl: true }); - setProcessedImageUrl(result.thumbnail_url); - } else { - logger.warn("rmbg_image_url_missing"); - setProcessedImageUrl(null); - } - setProcessedImageBase64(result.image_base64); - setProcessType("rmbg"); - - toast.success( - `抠图完成!图片已保存到相册。处理时间: ${result.processing_time?.toFixed(2) || "未知"}秒` - ); - } else { + const resultUrl = result.original_url || result.thumbnail_url; + if (!response.ok || !result.success || !resultUrl) { throw new Error(result.error || result.detail || "抠图处理失败"); } + + setProcessedImageUrl(resultUrl); + setProcessedImageBase64(null); + setProcessType("rmbg"); + toast.success( + `抠图完成!图片已保存到相册。处理时间: ${result.processing_time?.toFixed(2) || "未知"}秒` + ); } catch (error) { logger.error("rmbg_failed", error); toast.error( @@ -1027,62 +988,30 @@ export function ImageAnnotator({ } }; - // 变清晰处理 const handleEnhance = async () => { if (!image || !originalImageUrl) return; setIsEnhancing(true); try { - // 使用原图URL获取原图数据,而不是canvas的预览图 - const base64Data = await imageUrlToBase64(originalImageUrl); - logger.debug("enhance_source_prepared", { base64Length: base64Data.length }); - + const imageUrl = await resolveProcessingImageUrl(originalImageUrl); + const prompt = "画图标注-变清晰处理"; const result = await requestLongTaskResult({ endpoint: "/api/enhance", - payload: { - image_base64: base64Data, - prompt: "画图标注-变清晰处理", - }, - pollingParams: { - prompt: "画图标注-变清晰处理", - }, + payload: { imageUrl, prompt, includeBase64: false }, + pollingParams: { sourceImageUrl: imageUrl, prompt, includeBase64: "false" }, }); - if (result.success && result.image_base64) { - // 保存处理后的图片URL和Base64(优先使用original_url,确保下载的是处理后的原图) - logger.info("enhance_completed", { - hasOriginalUrl: !!result.original_url, - hasThumbnailUrl: !!result.thumbnail_url, - base64Length: result.image_base64?.length || 0, - }); - - // ✅ 验证:检查返回的URL是否是处理后的图片 - if (result.original_url) { - // 验证URL格式(应该包含enhance-orig) - if ( - !result.original_url.includes("enhance-orig") && - !result.original_url.includes("enhance-orig") - ) { - logger.warn("enhance_result_marker_missing"); - } - - setProcessedImageUrl(result.original_url); - } else if (result.thumbnail_url) { - logger.warn("enhance_original_url_missing", { hasThumbnailUrl: true }); - setProcessedImageUrl(result.thumbnail_url); - } else { - logger.warn("enhance_image_url_missing"); - setProcessedImageUrl(null); - } - setProcessedImageBase64(result.image_base64); - setProcessType("enhance"); - - toast.success( - `变清晰完成!图片已保存到相册。处理时间: ${result.processing_time?.toFixed(2) || "未知"}秒` - ); - } else { - throw new Error(result.error || result.detail || "变清晰处理失败"); + const resultUrl = result?.original_url || result?.thumbnail_url; + if (!result?.success || !resultUrl) { + throw new Error(result?.error || result?.detail || "变清晰处理失败"); } + + setProcessedImageUrl(resultUrl); + setProcessedImageBase64(null); + setProcessType("enhance"); + toast.success( + `变清晰完成!图片已保存到相册。处理时间: ${result.processing_time?.toFixed(2) || "未知"}秒` + ); } catch (error) { logger.error("enhance_failed", error); toast.error( @@ -1347,6 +1276,7 @@ export function ImageAnnotator({ }, body: JSON.stringify({ image_base64: base64Data, + includeBase64: false, prompt: `尺寸调整处理 - ${resizeCanvasWidth}x${resizeCanvasHeight}`, canvasWidth: resizeCanvasWidth, canvasHeight: resizeCanvasHeight, diff --git a/components/scene-fusion-view.tsx b/components/scene-fusion-view.tsx index 8ac28eb74..fcf7d27a4 100644 --- a/components/scene-fusion-view.tsx +++ b/components/scene-fusion-view.tsx @@ -1884,6 +1884,7 @@ export function SceneFusionView({ imageUrl: item.image, prompt: getModePrompt(mode), skipGallerySave: false, + includeBase64: false, }), }); const payload = await response.json(); @@ -1903,9 +1904,12 @@ export function SceneFusionView({ payload: { imageUrl: item.image, prompt: getModePrompt(mode), + includeBase64: false, }, pollingParams: { prompt: getModePrompt(mode), + sourceImageUrl: item.image, + includeBase64: "false", }, }); if (!payload?.success) { diff --git a/lib/ai/box-cutout/service.ts b/lib/ai/box-cutout/service.ts index 3c38ecad9..ee70ede30 100644 --- a/lib/ai/box-cutout/service.ts +++ b/lib/ai/box-cutout/service.ts @@ -204,6 +204,7 @@ export async function executeBoxCutoutJob( userId: params.userId, imageBuffer: croppedBuffer, imageBase64: croppedBuffer.toString("base64"), + includeBase64: false, sourceImageUrl: imageUrl, prompt: params.prompt || "框选抠图", chatId: params.chatId || null, diff --git a/lib/ai/canvas-agent-runtime/video-image-functions.ts b/lib/ai/canvas-agent-runtime/video-image-functions.ts index 003f94697..345b1a4f2 100644 --- a/lib/ai/canvas-agent-runtime/video-image-functions.ts +++ b/lib/ai/canvas-agent-runtime/video-image-functions.ts @@ -71,8 +71,8 @@ export async function processVideoCanvasImage( const { executeRmbgJob } = await import("@/lib/ai/rmbg/service"); const result = await executeRmbgJob({ userId: params.userId, - imageBuffer: await fetchImageBufferFromUrl(imageUrl), inputImageUrl: imageUrl, + includeBase64: false, sourceImageUrl: imageUrl, prompt: params.prompt, }); @@ -104,7 +104,8 @@ export async function processVideoCanvasImage( if (definition.route === "enhance") { const result = await requestLongTaskResult({ endpoint: resolveCanvasRuntimeEndpoint("/api/enhance", params.request.url), - payload: { imageUrl, scaleFactor: Number(args.scaleFactor) || 2 }, + payload: { imageUrl, scaleFactor: Number(args.scaleFactor) || 2, includeBase64: false }, + pollingParams: { sourceImageUrl: imageUrl, includeBase64: "false" }, headers: cookie ? { cookie } : undefined, timeoutMs: 10 * 60_000, }); @@ -119,6 +120,7 @@ export async function processVideoCanvasImage( headers: { "Content-Type": "application/json", ...(cookie ? { cookie } : {}) }, body: JSON.stringify({ image_url: imageUrl, + includeBase64: false, horizontal_angle: Number(args.horizontalAngle) || 0, vertical_angle: Number(args.verticalAngle) || 0, zoom: Number(args.zoom) || 0, diff --git a/lib/ai/runtime/direct-agent-image-edit-executor.ts b/lib/ai/runtime/direct-agent-image-edit-executor.ts index d60ec2b3f..d190d3ddb 100644 --- a/lib/ai/runtime/direct-agent-image-edit-executor.ts +++ b/lib/ai/runtime/direct-agent-image-edit-executor.ts @@ -14,7 +14,6 @@ import { } from "@/lib/ai/resize/service"; import { executeRmbgJob, - fetchImageBufferFromUrl, RmbgServiceError, } from "@/lib/ai/rmbg/service"; import { generateCanvasImage } from "@/lib/canvas/generate-image"; @@ -138,12 +137,14 @@ async function executeDirectAgentEnhanceJob(params: { prompt: params.prompt, chatId: params.chatId, messageId: params.messageId, + includeBase64: false, }, pollingParams: { prompt: params.prompt, chatId: params.chatId, messageId: params.messageId, sourceImageUrl: params.imageUrl, + includeBase64: "false", }, timeoutMs: 10 * 60 * 1000, headers: cookieHeader @@ -207,6 +208,7 @@ async function executeDirectAgentAngleEditJob(params: { endpoint, payload: { image_url: params.imageUrl, + includeBase64: false, horizontal_angle: params.options.horizontalAngle, vertical_angle: params.options.verticalAngle, zoom: params.options.zoom, @@ -512,11 +514,10 @@ export async function executeDirectAgentImageEditTool( } if (params.capability === "remove_background") { - const sourceBuffer = await fetchImageBufferFromUrl(params.sourceImageUrl); const result = await executeRmbgJob({ userId: params.userId, - imageBuffer: sourceBuffer, inputImageUrl: params.sourceImageUrl, + includeBase64: false, prompt: params.requestTextContent || "抠图处理", chatId: params.chatId, messageId: params.messageId, diff --git a/lib/canvas/capabilities/headless-executor.ts b/lib/canvas/capabilities/headless-executor.ts index 5f46f2567..6d923f142 100644 --- a/lib/canvas/capabilities/headless-executor.ts +++ b/lib/canvas/capabilities/headless-executor.ts @@ -302,6 +302,7 @@ async function executeForTarget( requestHeaders: params.requestHeaders, body: { image_url: target.sourceImageUrl, + includeBase64: false, horizontal_angle: asFiniteNumber(command.args.horizontalAngle) ?? 30, vertical_angle: asFiniteNumber(command.args.verticalAngle) ?? 0, zoom: asFiniteNumber(command.args.zoom) ?? 0, diff --git a/lib/canvas/operations/angle-edit.ts b/lib/canvas/operations/angle-edit.ts index efcaf3b26..767e34930 100644 --- a/lib/canvas/operations/angle-edit.ts +++ b/lib/canvas/operations/angle-edit.ts @@ -340,7 +340,7 @@ export async function executeAngleEditPOST(request: Request, trustedUserId: stri success: true, image_url: s3Result.original, thumbnail_url: s3Result.thumbnail, - image_base64: imageBase64Result, + image_base64: body.includeBase64 === false ? undefined : imageBase64Result, processing_time: processingTime, angles: { horizontal_angle: finalHorizontalAngle, diff --git a/lib/canvas/operations/enhance.ts b/lib/canvas/operations/enhance.ts index c8ebd8420..f41f6120f 100644 --- a/lib/canvas/operations/enhance.ts +++ b/lib/canvas/operations/enhance.ts @@ -388,6 +388,7 @@ async function processWithVip98kEnhance(params: { messageId: string | null; sourceImageUrl: string | null; scaleFactor: number; + includeBase64: boolean; }) { const startedAt = Date.now(); const result = await executeConfiguredVip98kTask({ @@ -408,8 +409,7 @@ async function processWithVip98kEnhance(params: { throw new Error(`VIP98K 变清晰结果下载失败(HTTP ${response.status})`); } const outputBuffer = Buffer.from(await response.arrayBuffer()); - const outputBase64 = outputBuffer.toString("base64"); - const uploaded = await uploadEnhanceImage(outputBase64, "image/png"); + const uploaded = await uploadEnhanceImage(outputBuffer, "image/png"); const [savedImage] = await db .insert(generatedImage) .values({ @@ -468,7 +468,7 @@ async function processWithVip98kEnhance(params: { return { success: true, - image_base64: outputBase64, + image_base64: params.includeBase64 ? outputBuffer.toString("base64") : undefined, thumbnail_url: uploaded.thumbnail, original_url: uploaded.original, processing_time: (Date.now() - startedAt) / 1000, @@ -634,6 +634,7 @@ async function executeFalEsrganFallback(params: { messageId: string | null; sourceImageUrl: string | null; requestedScaleFactor?: number; + includeBase64: boolean; reason: string; }) { const scaleFactor = params.requestedScaleFactor || 4; @@ -651,6 +652,7 @@ async function executeFalEsrganFallback(params: { prompt: params.prompt || "图片变清晰处理", chatId: params.chatId, messageId: params.messageId, + includeBase64: params.includeBase64, sourceImageUrls: params.sourceImageUrl ? [params.sourceImageUrl] : undefined, @@ -914,6 +916,7 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string messageId, sourceImageUrl, scaleFactor, + includeBase64, }); return NextResponse.json(payload); } catch (error) { @@ -1056,7 +1059,7 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string console.log(`[Enhance-RealESRGAN] ✅ 全部完成,总耗时: ${result.processingTime.toFixed(2)}秒`); return NextResponse.json({ success: true, - image_base64: result.imageBase64, + image_base64: includeBase64 ? result.imageBase64 : undefined, thumbnail_url: thumbnailUrl, original_url: originalUrl, processing_time: result.processingTime, @@ -1074,6 +1077,7 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string messageId, sourceImageUrl, requestedScaleFactor, + includeBase64, reason: error instanceof Error ? error.message : "RealESRGAN 备用服务失败", }); return NextResponse.json(fallbackPayload); @@ -1254,6 +1258,7 @@ export async function executeEnhancePOST(request: Request, trustedUserId: string messageId, sourceImageUrl, requestedScaleFactor, + includeBase64, reason: fetchError instanceof Error ? fetchError.message : "AOS 高清任务创建失败", }); return NextResponse.json(fallbackPayload); diff --git a/lib/scene-fusion/preprocess-product.ts b/lib/scene-fusion/preprocess-product.ts index d3252006a..87af441b0 100644 --- a/lib/scene-fusion/preprocess-product.ts +++ b/lib/scene-fusion/preprocess-product.ts @@ -18,7 +18,7 @@ export async function preprocessProductImageWithRmbg(params: { const response = await executeRemoveBackgroundPOST(new Request(new URL("/api/rmbg", request.url), { method: "POST", headers: { "Content-Type": "application/json", "X-Request-ID": `${requestId}:pre-rmbg` }, - body: JSON.stringify({ imageUrl: productImageUrl, prompt: "场景裂变预处理-抠图", skipGallerySave: true }), + body: JSON.stringify({ imageUrl: productImageUrl, prompt: "场景裂变预处理-抠图", skipGallerySave: true, includeBase64: false }), }), userId); const payload = await response.json(); if (!response.ok) { diff --git a/lib/video-canvas/image-operation.ts b/lib/video-canvas/image-operation.ts index 6d0413873..c6323b894 100644 --- a/lib/video-canvas/image-operation.ts +++ b/lib/video-canvas/image-operation.ts @@ -61,6 +61,7 @@ export async function executeImageOperation( : input.operation === "angle-edit" ? { image_url: input.imageUrl, + includeBase64: false, horizontal_angle: input.horizontalAngle, vertical_angle: input.verticalAngle, zoom: input.zoom, diff --git a/services/canvas/index.ts b/services/canvas/index.ts index 050dbd550..2c0b6c3fc 100644 --- a/services/canvas/index.ts +++ b/services/canvas/index.ts @@ -704,7 +704,7 @@ export const imageGenerationService = { const response = await fetch('/api/rmbg', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ imageUrl }), // 使用 imageUrl 参数 + body: JSON.stringify({ imageUrl, includeBase64: false }), }); const data = await response.json(); if (data.success && data.original_url) { @@ -780,22 +780,22 @@ export const imageGenerationService = { } ): Promise> { try { - const response = await fetch('/api/enhance', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ + const data = await requestLongTaskResult({ + endpoint: '/api/enhance', + payload: { imageUrl, scaleFactor: options?.scaleFactor, - }), + includeBase64: false, + }, + pollingParams: { sourceImageUrl: imageUrl, includeBase64: 'false' }, }); - const data = await response.json(); - if (data.success && data.original_url) { + if (data?.success && data.original_url) { return { success: true, data: { url: data.original_url } }; } - return { success: false, error: data.error || '图片增强失败' }; + return { success: false, error: data?.error || data?.detail || '图片增强失败' }; } catch (error) { logCatch(error, "enhance_image"); - return { success: false, error: '图片增强失败' }; + return { success: false, error: error instanceof Error ? error.message : '图片增强失败' }; } }, @@ -992,6 +992,7 @@ export const imageGenerationService = { headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ image_base64: base64, + includeBase64: false, canvasWidth: width, canvasHeight: height, prompt: '尺寸调整', @@ -1033,6 +1034,7 @@ export const imageGenerationService = { headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ image_url: params.imageUrl, + includeBase64: false, horizontal_angle: params.horizontalAngle, vertical_angle: params.verticalAngle, zoom: params.zoom, diff --git a/tests/routes/aos-image-transfer.test.ts b/tests/routes/aos-image-transfer.test.ts index c5f64200d..a84b18c96 100644 --- a/tests/routes/aos-image-transfer.test.ts +++ b/tests/routes/aos-image-transfer.test.ts @@ -93,3 +93,22 @@ test("canvas cutout keeps the archived PNG as the original and skips production expect(result.image_base64).toBeUndefined(); expect(calls).toEqual([`${input}?imageInfo`, endpoint, `${endpoint}/test-aos-task`, "aos-rmbg-test-aos-task"]); }); + +test("a batch enhancement completed on submission returns only stored image links", async () => { + const { load, calls, endpoint } = testImageTransfer("scale"); + const enhance = load("lib/canvas/operations/enhance.ts"); + const response = await enhance.executeEnhancePOST( + new Request("https://app.example/enhance", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ imageUrl: input, scaleFactor: 2, includeBase64: false }), + }), + "test-user", + ); + expect(response.status).toBe(200); + const result = await response.json(); + expect(result.original_url).toBe(archived); + expect(result.thumbnail_url).toBeTruthy(); + expect(result).not.toHaveProperty("image_base64"); + expect(calls).toEqual([`${input}?imageInfo`, endpoint, `${endpoint}/test-aos-task`, "aos-enhance-test-aos-task"]); +}); diff --git a/tests/routes/video-canvas-tasks.test.ts b/tests/routes/video-canvas-tasks.test.ts index 3c597085c..ed7714adb 100644 --- a/tests/routes/video-canvas-tasks.test.ts +++ b/tests/routes/video-canvas-tasks.test.ts @@ -356,6 +356,7 @@ test("angle operation sends normalized numeric fields and accepts the dedicated const handler = async (req: Request) => { expect(await req.json()).toEqual({ image_url: "https://example.com/source.png", + includeBase64: false, horizontal_angle: 180, vertical_angle: 45, zoom: 5,