fix: 修复enhance API中image字段可能是base64字符串而非URL的问题,添加URL验证
This commit is contained in:
parent
f239642716
commit
c68c1a1964
@ -436,16 +436,23 @@ export async function POST(request: NextRequest) {
|
||||
// 返回的是base64
|
||||
enhancedImageBase64 = taskResult.data.image_base64;
|
||||
} else if (taskResult.data.image) {
|
||||
// 返回的是URL,需要下载
|
||||
const imageResponse = await fetch(taskResult.data.image);
|
||||
if (!imageResponse.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: "变清晰处理失败", detail: "无法下载处理后的图片" },
|
||||
{ status: 500 }
|
||||
);
|
||||
// 检查是否是URL(以http://或https://开头)
|
||||
const imageData = taskResult.data.image;
|
||||
if (typeof imageData === "string" && (imageData.startsWith("http://") || imageData.startsWith("https://"))) {
|
||||
// 返回的是URL,需要下载
|
||||
const imageResponse = await fetch(imageData);
|
||||
if (!imageResponse.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: "变清晰处理失败", detail: "无法下载处理后的图片" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
const imageBuffer = await imageResponse.arrayBuffer();
|
||||
enhancedImageBase64 = Buffer.from(imageBuffer).toString("base64");
|
||||
} else {
|
||||
// 返回的是base64字符串(直接使用)
|
||||
enhancedImageBase64 = imageData;
|
||||
}
|
||||
const imageBuffer = await imageResponse.arrayBuffer();
|
||||
enhancedImageBase64 = Buffer.from(imageBuffer).toString("base64");
|
||||
} else {
|
||||
return NextResponse.json(
|
||||
{ error: "变清晰处理失败", detail: "轮询结果未包含图片数据" },
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user