chore: harden world labs upload logging
This commit is contained in:
parent
9e8aa5a543
commit
ccf316630b
@ -1,5 +1,6 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { auth } from "@/app/(auth)/auth";
|
import { auth } from "@/app/(auth)/auth";
|
||||||
|
import { createLogger } from "@/lib/observability/logger";
|
||||||
import { WorldLabsApiError, worldLabsRequest } from "@/lib/worldlabs/client";
|
import { WorldLabsApiError, worldLabsRequest } from "@/lib/worldlabs/client";
|
||||||
import {
|
import {
|
||||||
disableWorldLabsProvider,
|
disableWorldLabsProvider,
|
||||||
@ -11,6 +12,8 @@ import type { WorldLabsPrepareUploadResponse } from "@/lib/worldlabs/types";
|
|||||||
export const runtime = "nodejs";
|
export const runtime = "nodejs";
|
||||||
export const maxDuration = 120;
|
export const maxDuration = 120;
|
||||||
|
|
||||||
|
const logger = createLogger("world-labs-upload");
|
||||||
|
|
||||||
const ALLOWED_IMAGE_TYPES = new Set(["image/png", "image/jpeg", "image/webp"]);
|
const ALLOWED_IMAGE_TYPES = new Set(["image/png", "image/jpeg", "image/webp"]);
|
||||||
const ALLOWED_VIDEO_TYPES = new Set([
|
const ALLOWED_VIDEO_TYPES = new Set([
|
||||||
"video/mp4",
|
"video/mp4",
|
||||||
@ -229,12 +232,12 @@ export async function POST(request: Request) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.info("[WorldLabsUpload] success", {
|
logger.info("upload completed", {
|
||||||
elapsedMs: Date.now() - startedAt,
|
elapsedMs: Date.now() - startedAt,
|
||||||
providerId: config.providerId || null,
|
providerId: config.providerId || null,
|
||||||
kind: isImage ? "image" : "video",
|
kind: isImage ? "image" : "video",
|
||||||
size: file.size,
|
size: file.size,
|
||||||
mediaAssetId,
|
mediaAssetIdLength: mediaAssetId.length,
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
@ -262,12 +265,11 @@ export async function POST(request: Request) {
|
|||||||
? lastError
|
? lastError
|
||||||
: new Error("上传 World Labs 媒体失败");
|
: new Error("上传 World Labs 媒体失败");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("[WorldLabsUpload] failed", {
|
logger.error("upload failed", error, {
|
||||||
elapsedMs: Date.now() - startedAt,
|
elapsedMs: Date.now() - startedAt,
|
||||||
providerId: providerForLog,
|
providerId: providerForLog,
|
||||||
kind: kindForLog,
|
kind: kindForLog,
|
||||||
size: sizeForLog,
|
size: sizeForLog,
|
||||||
error: error instanceof Error ? error.message : String(error),
|
|
||||||
});
|
});
|
||||||
if (error instanceof WorldLabsApiError) {
|
if (error instanceof WorldLabsApiError) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
|
|||||||
@ -32,6 +32,7 @@ const files = [
|
|||||||
"app/api/canvas/detail-plan/route.ts",
|
"app/api/canvas/detail-plan/route.ts",
|
||||||
"app/api/scene-fusion/route.ts",
|
"app/api/scene-fusion/route.ts",
|
||||||
"app/api/pick-object/route.ts",
|
"app/api/pick-object/route.ts",
|
||||||
|
"app/api/canvas/world/upload/route.ts",
|
||||||
];
|
];
|
||||||
|
|
||||||
const consolePattern = /\bconsole\.(log|warn|error|info|debug)\b/g;
|
const consolePattern = /\bconsole\.(log|warn|error|info|debug)\b/g;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user