fix: avoid premature psd parse timeout

This commit is contained in:
Your Name 2026-06-02 11:27:27 +08:00
parent ea1bc4c78b
commit caf9eb7290
2 changed files with 22 additions and 3 deletions

View File

@ -25,6 +25,7 @@ import { failTimedOutAgentPsdTemplates } from "@/lib/agents/psd-template-timeout
import { uploadFile } from "@/lib/storage/service"; import { uploadFile } from "@/lib/storage/service";
export const runtime = "nodejs"; export const runtime = "nodejs";
export const maxDuration = 1800;
function jsonError(status: number, error: string) { function jsonError(status: number, error: string) {
const payload: AgentPsdTemplateMutationResponse = { const payload: AgentPsdTemplateMutationResponse = {
@ -291,6 +292,13 @@ export async function POST(
}); });
} }
await updateParseProgress({
templateId: id,
updatedBy: session.user.id,
progress: 24,
stage: "正在解析 PSD 图层结构与预览",
error: undefined,
});
const parsedTemplate = await parsePsdTemplateFile(fileBuffer); const parsedTemplate = await parsePsdTemplateFile(fileBuffer);
if (parsedTemplate.layers.length === 0) { if (parsedTemplate.layers.length === 0) {
@ -301,7 +309,7 @@ export async function POST(
templateId: id, templateId: id,
updatedBy: session.user.id, updatedBy: session.user.id,
progress: 42, progress: 42,
stage: "正在生成模板预览", stage: "正在上传模板预览",
error: undefined, error: undefined,
}); });

View File

@ -7,8 +7,19 @@ import {
} from "@/lib/agents/psd-template-config"; } from "@/lib/agents/psd-template-config";
import { readAgentPsdTemplates } from "@/lib/agents/psd-template-settings"; import { readAgentPsdTemplates } from "@/lib/agents/psd-template-settings";
export const AGENT_PSD_TEMPLATE_QUICK_PARSE_TIMEOUT_MS = 8 * 60 * 1000; function getEnvPositiveInt(name: string, fallback: number) {
export const AGENT_PSD_TEMPLATE_ASSET_BACKFILL_TIMEOUT_MS = 20 * 60 * 1000; const parsed = Number.parseInt(process.env[name] || "", 10);
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
}
export const AGENT_PSD_TEMPLATE_QUICK_PARSE_TIMEOUT_MS = getEnvPositiveInt(
"AGENT_PSD_TEMPLATE_QUICK_PARSE_TIMEOUT_MS",
15 * 60 * 1000
);
export const AGENT_PSD_TEMPLATE_ASSET_BACKFILL_TIMEOUT_MS = getEnvPositiveInt(
"AGENT_PSD_TEMPLATE_ASSET_BACKFILL_TIMEOUT_MS",
20 * 60 * 1000
);
function getTemplateUpdatedAtTime(template: AgentPsdTemplate) { function getTemplateUpdatedAtTime(template: AgentPsdTemplate) {
const updatedAt = new Date(template.updatedAt).getTime(); const updatedAt = new Date(template.updatedAt).getTime();