feat(*): 创作工作台 - 完善画布生成、模型定价与创建流程
This commit is contained in:
1 parent
a20df86cbd
commit
982021be93
39 files changed
+735
-242
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { buildImageResolutionOptions } from "./image-resolution-tiers";
|
||||
import { isImageResolutionTier } from "./image-quality";
|
||||
import type { ImageCapabilityConfig } from "./model-capabilities";
|
||||
|
||||
/** 旧图片价格档把 1K/2K/4K 存在 quality;只在读取价格条件时转换。 */
|
||||
export function normalizeImagePriceSelector(input: Record<string, string>) {
|
||||
const selector = { ...input };
|
||||
for (const key of ["quality", "resolution", "size"] as const) {
|
||||
if (selector[key]) selector[key] = selector[key].trim().toLowerCase();
|
||||
}
|
||||
if (isImageResolutionTier(selector.quality) && (!selector.resolution || selector.resolution === "*")) {
|
||||
selector.resolution = selector.quality;
|
||||
delete selector.quality;
|
||||
}
|
||||
return selector;
|
||||
}
|
||||
|
||||
export function imagePriceSelector(quality: string, size: string, profile?: ImageCapabilityConfig): Record<string, string> {
|
||||
quality = quality.trim().toLowerCase();
|
||||
size = size.trim().toLowerCase();
|
||||
const selector: Record<string, string> = {};
|
||||
if (quality && quality !== "auto" && quality !== "any") selector.quality = quality;
|
||||
if (size && size !== "auto" && size !== "any") selector.size = size;
|
||||
const pixel = buildImageResolutionOptions([size])[0];
|
||||
if (pixel) {
|
||||
selector.resolution = profile?.size.presets?.find((preset) => preset.size.toLowerCase() === size)?.tier || pixel.tier;
|
||||
} else if (isImageResolutionTier(quality)) {
|
||||
selector.resolution = quality;
|
||||
} else if (profile?.size.parameter === "aspect_ratio") {
|
||||
const tier = ({ low: "1k", medium: "2k", high: "4k" } as Record<string, string>)[quality];
|
||||
if (tier && profile.quality.supported) selector.resolution = tier;
|
||||
else if (!profile.quality.supported) {
|
||||
const tiers = new Set(profile.size.presets?.filter((preset) => preset.ratio === size).map((preset) => preset.tier));
|
||||
if (tiers.size === 1) selector.resolution = [...tiers][0];
|
||||
}
|
||||
}
|
||||
return selector;
|
||||
}
|
||||
Reference in new issue
Block a user