fix(admin): 渠道模型 - 补充 1440P 分辨率并支持自定义档位

This commit is contained in:
ddCat
2026-08-15 22:11:02 +08:00
parent b9d432f218
commit e26ed02c2e
5 changed files with 24 additions and 3 deletions

View File

@@ -540,6 +540,9 @@ func ratioValue(value string) float64 {
func normalizeResolution(value string) string {
value = strings.ToLower(strings.TrimSpace(value))
value = strings.TrimSuffix(value, "p")
if value == "2k" {
return "1440p"
}
if value == "4k" {
return "2160p"
}

View File

@@ -82,3 +82,18 @@ func TestDefaultVideoCapabilityUsesProtocolSpecificResolutionTiers(t *testing.T)
})
}
}
func TestNormalizeResolutionSupportsCommonAliases(t *testing.T) {
tests := map[string]string{
"1440": "1440p",
"1440p": "1440p",
"2K": "1440p",
"4K": "2160p",
"768P": "768p",
}
for input, want := range tests {
if got := normalizeResolution(input); got != want {
t.Fatalf("normalizeResolution(%q) = %q, want %q", input, got, want)
}
}
}

View File

@@ -3,9 +3,9 @@ import type { ReactNode } from "react";
import { defaultImageCapabilityConfig, defaultModelCapabilityConfig, type ImageCapabilityConfig, type ModelCapabilityConfig, type VideoCapabilityConfig } from "@/lib/model-capabilities";
import type { ModelProtocol } from "@/lib/model-protocols";
import { VIDEO_RESOLUTION_CAPABILITY_OPTIONS } from "@/lib/video-generation-options";
const ratioOptions = ["16:9", "9:16", "1:1", "4:3", "3:4", "21:9"];
const resolutionOptions = ["480p", "720p", "1080p", "2160p"];
const operationOptions = [
{ label: "文生视频", value: "text_to_video" },
{ label: "图生视频", value: "image_to_video" },
@@ -35,6 +35,7 @@ export function ModelCapabilityEditor({ value, onChange, protocol, capability =
const updateReferences = (patch: Partial<VideoCapabilityConfig["references"]>) => update({ references: { ...profile.references, ...patch } });
const updateDuration = (patch: Partial<VideoCapabilityConfig["duration"]>) => update({ duration: { ...profile.duration, ...patch } });
const durationValues = (profile.duration.values || []).join(",");
const resolutionOptions = Array.from(new Set([...VIDEO_RESOLUTION_CAPABILITY_OPTIONS, ...profile.resolutions]));
return (
<div className="space-y-3 rounded-md border border-border/70 bg-muted/10 p-3">
@@ -75,7 +76,7 @@ export function ModelCapabilityEditor({ value, onChange, protocol, capability =
<div className="grid gap-2 sm:grid-cols-2">
<Field label="画面比例"><Select mode="multiple" className="w-full" disabled={disabled} value={profile.ratios} options={ratioOptions.map((item) => ({ label: item, value: item }))} onChange={(ratios) => update({ ratios, defaultRatio: ratios.includes(profile.defaultRatio) ? profile.defaultRatio : ratios[0] || "16:9" })} /></Field>
<Field label="默认比例"><Select className="w-full" disabled={disabled} value={profile.defaultRatio} options={profile.ratios.map((item) => ({ label: item, value: item }))} onChange={(defaultRatio) => update({ defaultRatio })} /></Field>
<Field label="输出分辨率"><Select mode="multiple" className="w-full" disabled={disabled} value={profile.resolutions} options={resolutionOptions.map((item) => ({ label: item.toUpperCase(), value: item }))} onChange={(resolutions) => update({ resolutions, defaultResolution: resolutions.includes(profile.defaultResolution) ? profile.defaultResolution : resolutions[0] || "720p" })} /></Field>
<Field label="输出分辨率"><Select mode="tags" className="w-full" disabled={disabled} value={profile.resolutions} tokenSeparators={[","]} placeholder="选择标准档位或输入 768p 等模型专属值" options={resolutionOptions.map((item) => ({ label: item.toUpperCase(), value: item }))} onChange={(resolutions) => update({ resolutions, defaultResolution: resolutions.includes(profile.defaultResolution) ? profile.defaultResolution : resolutions[0] || "720p" })} /></Field>
<Field label="默认分辨率"><Select className="w-full" disabled={disabled} value={profile.defaultResolution} options={profile.resolutions.map((item) => ({ label: item.toUpperCase(), value: item }))} onChange={(defaultResolution) => update({ defaultResolution })} /></Field>
</div>
<div className="grid gap-2 sm:grid-cols-2">

View File

@@ -1,5 +1,6 @@
export const VIDEO_DURATION_OPTIONS = [6, 9, 10, 15] as const;
export const VIDEO_RESOLUTION_OPTIONS = [480, 720, 1080, 1440, 2160] as const;
export const VIDEO_RESOLUTION_CAPABILITY_OPTIONS = VIDEO_RESOLUTION_OPTIONS.map((value) => `${value}p`);
export const VIDEO_DURATION_MIN = 1;
export function normalizeVideoDuration(value: string | number | undefined) {

View File

@@ -1,11 +1,12 @@
import { describe, expect, test } from "bun:test";
import { defaultModelCapabilityConfig } from "../src/lib/model-capabilities";
import { normalizeVideoResolution, VIDEO_RESOLUTION_OPTIONS } from "../src/lib/video-generation-options";
import { normalizeVideoResolution, VIDEO_RESOLUTION_CAPABILITY_OPTIONS, VIDEO_RESOLUTION_OPTIONS } from "../src/lib/video-generation-options";
describe("video generation resolution options", () => {
test("统一档位包含 1440P 与 4K,并识别常见别名", () => {
expect(VIDEO_RESOLUTION_OPTIONS).toEqual([480, 720, 1080, 1440, 2160]);
expect(VIDEO_RESOLUTION_CAPABILITY_OPTIONS).toEqual(["480p", "720p", "1080p", "1440p", "2160p"]);
expect(normalizeVideoResolution("2k")).toBe("1440");
expect(normalizeVideoResolution("1440p")).toBe("1440");
expect(normalizeVideoResolution("4K")).toBe("2160");