chore: govern enhance pro api logging
This commit is contained in:
parent
f4d272c7ff
commit
58f6f5f249
@ -28,9 +28,12 @@ import {
|
||||
type EnhanceProOutputFormat,
|
||||
type EnhanceProSubjectDetection,
|
||||
} from "@/lib/enhance-pro/config";
|
||||
import { createLogger } from "@/lib/observability/logger";
|
||||
import { calculateEnhanceProPointsEstimate } from "@/lib/points/config";
|
||||
import { uploadFile } from "@/lib/storage/service";
|
||||
|
||||
const logger = createLogger("enhance-pro-api");
|
||||
|
||||
const ENHANCE_PRO_CREATE_TIMEOUT_MS = 120_000;
|
||||
const ENHANCE_PRO_TASK_POLL_INTERVAL_MS = 1_500;
|
||||
const ENHANCE_PRO_MODEL_ID = "krea-topaz-generative";
|
||||
@ -207,7 +210,7 @@ async function createThumbnail(buffer: Buffer): Promise<Buffer> {
|
||||
.jpeg({ quality: 82 })
|
||||
.toBuffer();
|
||||
} catch (error) {
|
||||
console.error("[Enhance Pro] 生成缩略图失败,回退使用原图:", error);
|
||||
logger.warn("thumbnail_creation_failed", error);
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
@ -253,7 +256,7 @@ async function getImageDimensionsFromBuffer(buffer: Buffer) {
|
||||
height: metadata.height || 1024,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("[Enhance Pro] 获取图片尺寸失败,回退默认值:", error);
|
||||
logger.warn("image_dimension_detection_failed", error);
|
||||
return {
|
||||
width: 1024,
|
||||
height: 1024,
|
||||
@ -512,7 +515,7 @@ async function finalizeEnhanceProTaskResult(params: {
|
||||
}
|
||||
}
|
||||
} catch (assetError) {
|
||||
console.error("[Enhance Pro] MediaAsset 注册失败:", assetError);
|
||||
logger.warn("media_asset_registration_failed", assetError);
|
||||
}
|
||||
|
||||
finalizedImages.push({
|
||||
@ -670,9 +673,9 @@ async function refundEnhanceProPointsForFailedTask(
|
||||
});
|
||||
|
||||
if (!refundResult.ok) {
|
||||
console.error("[Points] Failed to refund Enhance Pro points:", {
|
||||
logger.error("points_refund_failed", {
|
||||
taskId: task.id,
|
||||
errorMessage,
|
||||
errorLength: errorMessage.length,
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
@ -725,7 +728,7 @@ async function markEnhanceProTaskFailed(taskId: string, errorMessage: string) {
|
||||
try {
|
||||
refundedPoints = await refundEnhanceProPointsForFailedTask(task, errorMessage);
|
||||
} catch (refundError) {
|
||||
console.error("[Points] Failed to refund failed Enhance Pro task:", refundError);
|
||||
logger.error("failed_task_refund_error", refundError, { taskId });
|
||||
}
|
||||
}
|
||||
|
||||
@ -845,7 +848,7 @@ async function finalizeEnhanceProTask(
|
||||
const chargeResult = await consumeEnhanceProPointsOnce(claimedTask, request);
|
||||
pointsCharged = chargeResult.chargeApplied === true;
|
||||
} catch (pointsError) {
|
||||
console.error("[Points] Failed to consume Enhance Pro points:", pointsError);
|
||||
logger.error("points_charge_failed", pointsError, { taskId: claimedTask.id });
|
||||
}
|
||||
}
|
||||
|
||||
@ -982,7 +985,7 @@ export async function GET(request: NextRequest) {
|
||||
await markEnhanceProTaskRunning(task.id);
|
||||
return buildEnhanceProTaskPendingResponse(task.id);
|
||||
} catch (error) {
|
||||
console.error("[Enhance Pro API][TaskStatus] 错误:", error);
|
||||
logger.error("task_status_request_failed", error);
|
||||
return NextResponse.json(
|
||||
{ error: "服务器内部错误", detail: error instanceof Error ? error.message : "未知错误" },
|
||||
{ status: 500 },
|
||||
@ -1221,7 +1224,7 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
return buildEnhanceProTaskPendingResponse(createdTask.id);
|
||||
} catch (error) {
|
||||
console.error("[Enhance Pro API] 错误:", error);
|
||||
logger.error("create_request_failed", error);
|
||||
return NextResponse.json(
|
||||
{ error: "服务器内部错误", detail: error instanceof Error ? error.message : "未知错误" },
|
||||
{ status: 500 },
|
||||
|
||||
@ -36,6 +36,7 @@ const files = [
|
||||
"app/api/angle-edit/route.ts",
|
||||
"app/api/layer-split/route.ts",
|
||||
"app/api/enhance/pro/config/route.ts",
|
||||
"app/api/enhance/pro/route.ts",
|
||||
"app/api/product-planning/analyze-image/route.ts",
|
||||
"app/api/product-planning/analyze-sku/route.ts",
|
||||
"app/api/product-planning/analyze/route.ts",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user