Your Name e8a3212b35
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
feat: persist style pro history and model pricing
2026-05-16 21:28:00 +08:00

59 lines
1.7 KiB
TypeScript

import { NextResponse } from "next/server";
import { auth } from "@/app/(auth)/auth";
import { getSystemSetting, getUserById } from "@/lib/db/queries";
import {
findStyleProImageModelByRef,
getStyleProImageModelEntries,
toPublicStyleProModelOption,
} from "@/lib/style-pro/model-options";
import {
STYLE_PRO_CONFIG_KEY,
normalizeStyleProConfig,
} from "@/lib/style-pro/config";
export const dynamic = "force-dynamic";
export async function GET() {
try {
const session = await auth();
if (!session?.user?.id) {
return NextResponse.json(
{ success: false, error: "未登录" },
{ status: 401 }
);
}
const currentUser = await getUserById({ id: session.user.id }).catch(
() => null
);
const includeHidden =
session.user.type === "admin" || Boolean(currentUser?.isHighVip);
const [entries, setting] = await Promise.all([
getStyleProImageModelEntries({ includeHidden }),
getSystemSetting({ key: STYLE_PRO_CONFIG_KEY }).catch(() => null),
]);
const config = normalizeStyleProConfig(setting?.value);
const configuredDefault = findStyleProImageModelByRef(
entries,
config.modelId
);
const defaultEntry =
configuredDefault ||
entries.find((entry) => entry.model.isDefault) ||
entries[0] ||
null;
return NextResponse.json({
success: true,
defaultModelId: defaultEntry?.model.id || null,
models: entries.map(toPublicStyleProModelOption),
});
} catch (error) {
console.error("[Style Pro Model Options] Failed:", error);
return NextResponse.json(
{ success: false, error: "获取风格化 PRO 生图模型失败" },
{ status: 500 }
);
}
}