45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { auth } from "@/app/(auth)/auth";
|
|
import {
|
|
getEditableAgentPsdTemplateLayers,
|
|
type AgentPsdTemplateListResponse,
|
|
} from "@/lib/agents/psd-template-config";
|
|
import { readAgentPsdTemplates } from "@/lib/agents/psd-template-settings";
|
|
|
|
export const runtime = "nodejs";
|
|
export const dynamic = "force-dynamic";
|
|
|
|
function jsonError(status: number, error: string) {
|
|
const payload: AgentPsdTemplateListResponse = {
|
|
success: false,
|
|
templates: [],
|
|
error,
|
|
};
|
|
return NextResponse.json(payload, { status });
|
|
}
|
|
|
|
export async function GET() {
|
|
const session = await auth().catch(() => null);
|
|
if (!session?.user?.id) {
|
|
return jsonError(401, "未登录");
|
|
}
|
|
|
|
try {
|
|
const templates = (await readAgentPsdTemplates())
|
|
.filter((template) => template.status === "active")
|
|
.map((template) => ({
|
|
...template,
|
|
layers: getEditableAgentPsdTemplateLayers(template),
|
|
}))
|
|
.filter((template) => template.layers.length > 0);
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
templates,
|
|
} satisfies AgentPsdTemplateListResponse);
|
|
} catch (error) {
|
|
console.error("[PSD Templates] list failed:", error);
|
|
return jsonError(503, "PSD 模板读取失败");
|
|
}
|
|
}
|