59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { auth } from "@/app/(auth)/auth";
|
|
import { getSystemSetting } from "@/lib/db/queries";
|
|
import {
|
|
AI_WASH_CONFIG_KEY,
|
|
normalizeAiWashConfig,
|
|
sanitizeAiWashConfigForClient,
|
|
} from "@/lib/ai-wash/config";
|
|
import {
|
|
findStyleProImageModelByRef,
|
|
getStyleProImageModelEntries,
|
|
toPublicStyleProModelOption,
|
|
} from "@/lib/style-pro/model-options";
|
|
import { createLogger } from "@/lib/observability/logger";
|
|
|
|
const logger = createLogger("ai-wash-config-api");
|
|
|
|
export async function GET() {
|
|
try {
|
|
const session = await auth();
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json({ error: "未授权,请先登录" }, { status: 401 });
|
|
}
|
|
|
|
const setting = await getSystemSetting({ key: AI_WASH_CONFIG_KEY });
|
|
const config = normalizeAiWashConfig(setting?.value);
|
|
const lockedModelRefs = Array.from(
|
|
new Set(
|
|
config.presets
|
|
.flatMap((preset) => [
|
|
preset.modelId,
|
|
...preset.controls.flatMap((control) =>
|
|
control.levels.map((level) => level.modelId)
|
|
),
|
|
])
|
|
.map((item) => String(item || "").trim())
|
|
.filter(Boolean)
|
|
)
|
|
);
|
|
const modelEntries =
|
|
lockedModelRefs.length > 0
|
|
? await getStyleProImageModelEntries({ includeHidden: true })
|
|
: [];
|
|
const lockedModels = lockedModelRefs
|
|
.map((modelRef) => findStyleProImageModelByRef(modelEntries, modelRef))
|
|
.filter(Boolean)
|
|
.map((entry) => toPublicStyleProModelOption(entry!));
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
config: sanitizeAiWashConfigForClient(config),
|
|
lockedModels,
|
|
});
|
|
} catch (error) {
|
|
logger.error("config_fetch_failed", error);
|
|
return NextResponse.json({ error: "获取 AI洗图 配置失败" }, { status: 500 });
|
|
}
|
|
}
|