80 lines
2.5 KiB
TypeScript
80 lines
2.5 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { auth } from "@/app/(auth)/auth";
|
|
import { getModelGenerationCreditCost } from "@/lib/ai/image-model-pricing";
|
|
import { getSystemSetting } from "@/lib/db/queries";
|
|
import {
|
|
findStyleProImageModelByRef,
|
|
getStyleProImageModelDisplayEntries,
|
|
getStyleProImageModelEntries,
|
|
sortStyleProImageModelEntries,
|
|
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 [displayEntries, entries, realisticModelEntries, setting] =
|
|
await Promise.all([
|
|
getStyleProImageModelDisplayEntries({ includeHidden: false }),
|
|
getStyleProImageModelEntries({ includeHidden: false }),
|
|
getStyleProImageModelEntries({ includeHidden: true }),
|
|
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;
|
|
const realisticFirstModel = findStyleProImageModelByRef(
|
|
realisticModelEntries,
|
|
config.realisticFirstModelId
|
|
);
|
|
const realisticSecondModel = findStyleProImageModelByRef(
|
|
realisticModelEntries,
|
|
config.realisticSecondModelId
|
|
);
|
|
const realisticUnitCost =
|
|
realisticFirstModel && realisticSecondModel
|
|
? getModelGenerationCreditCost(realisticFirstModel.model as any, "image", {
|
|
imageSize: config.imageSize || "2K",
|
|
}) +
|
|
getModelGenerationCreditCost(realisticSecondModel.model as any, "image", {
|
|
imageSize: config.imageSize || "2K",
|
|
})
|
|
: 0;
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
defaultModelId: defaultEntry?.model.id || null,
|
|
realisticUnitCost,
|
|
models: sortStyleProImageModelEntries(displayEntries).map(
|
|
toPublicStyleProModelOption
|
|
),
|
|
});
|
|
} catch (error) {
|
|
console.error("[Style Pro Model Options] Failed:", error);
|
|
return NextResponse.json(
|
|
{ success: false, error: "获取风格化 PRO 生图模型失败" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|