Merge branch 'main' of gitee.com:wg123/video-gen into main

This commit is contained in:
18610128193
2026-07-01 10:18:26 +08:00
8 changed files with 698 additions and 57 deletions
File diff suppressed because one or more lines are too long
+36 -36
View File
@@ -1,37 +1,37 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap" rel="stylesheet" />
<title>后台管理</title>
<script>
(function() {
var cached = localStorage.getItem('siteInfo');
if (cached) {
try {
var info = JSON.parse(cached);
if (info.siteName) {
document.title = info.siteName + ' - 管理后台';
}
if (info.siteLogo) {
var link = document.querySelector('link[rel="icon"]');
if (link) {
link.href = info.siteLogo;
link.type = 'image/png';
}
}
} catch (e) {}
}
})();
</script>
<script type="module" crossorigin src="/assets/index-Yj3EUzSB.js"></script>
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap" rel="stylesheet" />
<title>后台管理</title>
<script>
(function() {
var cached = localStorage.getItem('siteInfo');
if (cached) {
try {
var info = JSON.parse(cached);
if (info.siteName) {
document.title = info.siteName + ' - 管理后台';
}
if (info.siteLogo) {
var link = document.querySelector('link[rel="icon"]');
if (link) {
link.href = info.siteLogo;
link.type = 'image/png';
}
}
} catch (e) {}
}
})();
</script>
<script type="module" crossorigin src="/assets/index-ChXF-ot2.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-D7ShJUt4.css">
</head>
<body>
<div id="root"></div>
</body>
</html>
</head>
<body>
<div id="root"></div>
</body>
</html>
@@ -17,6 +17,9 @@ interface VideoEngine {
supportedRatios: string[];
supportedResolutions: string[];
supportedDurations: number[];
maxDuration: number;
maxImageCount: number;
maxVideoCount: number;
isActive: boolean;
priority: number;
}
@@ -66,6 +69,9 @@ const AdminVideoEngines: React.FC = () => {
supported_ratios: JSON.stringify(values.supportedRatios || []),
supported_resolutions: JSON.stringify(values.supportedResolutions || []),
supported_durations: JSON.stringify(values.supportedDurations || []),
max_duration: values.maxDuration ?? 15,
max_image_count: values.maxImageCount ?? 5,
max_video_count: values.maxVideoCount ?? 2,
is_active: values.isActive ?? true,
priority: values.priority ?? 0,
};
@@ -103,6 +109,9 @@ const AdminVideoEngines: React.FC = () => {
form.resetFields();
form.setFieldsValue({
isActive: true, priority: 0,
maxDuration: 15,
maxImageCount: 5,
maxVideoCount: 2,
supportedRatios: ['16:9', '4:3', '1:1', '3:4', '9:16', '21:9'],
supportedResolutions: ['480p', '720p', '1080p'],
supportedDurations: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
@@ -142,6 +151,14 @@ const AdminVideoEngines: React.FC = () => {
title: '支持时长', dataIndex: 'supportedDurations', width: 120,
render: (d: number[]) => <Tag color="orange">{d?.length ? `${Math.min(...d)}-${Math.max(...d)}s` : '-'}</Tag>,
},
{
title: '最大图片', dataIndex: 'maxImageCount', width: 100,
render: (v: number) => <Tag color="purple">{v} </Tag>,
},
{
title: '最大视频', dataIndex: 'maxVideoCount', width: 100,
render: (v: number) => <Tag color="cyan">{v} </Tag>,
},
{
title: '状态', dataIndex: 'isActive', width: 80,
render: (v: boolean) => <Tag color={v ? 'green' : 'default'}>{v ? '启用' : '停用'}</Tag>,
@@ -234,6 +251,17 @@ const AdminVideoEngines: React.FC = () => {
} />
</Form.Item>
</div>
<div style={{ display: 'flex', gap: 16 }}>
<Form.Item name="maxDuration" label="最大时长(秒)" style={{ flex: 1 }}>
<Input type="number" size="large" />
</Form.Item>
<Form.Item name="maxImageCount" label="最大图片数量" style={{ flex: 1 }}>
<Input type="number" size="large" />
</Form.Item>
<Form.Item name="maxVideoCount" label="最大视频数量" style={{ flex: 1 }}>
<Input type="number" size="large" />
</Form.Item>
</div>
<div style={{ display: 'flex', gap: 16 }}>
<Form.Item name="priority" label="优先级">
<Select size="large" options={[
@@ -0,0 +1,27 @@
"""add max image and video count to video engines
Revision ID: f7a3b2c1d4e5
Revises: e5f260ed1459
Create Date: 2026-07-01 00:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
revision: str = 'f7a3b2c1d4e5'
down_revision: Union[str, None] = 'e5f260ed1459'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.add_column('video_engines', sa.Column('max_image_count', sa.Integer(), server_default='5', nullable=False))
op.add_column('video_engines', sa.Column('max_video_count', sa.Integer(), server_default='2', nullable=False))
def downgrade() -> None:
op.drop_column('video_engines', 'max_video_count')
op.drop_column('video_engines', 'max_image_count')
+51 -21
View File
@@ -48,40 +48,70 @@ async def get_credit_ratios(
current_user: User = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
async def get_ratios_for_engine_type(gen_type: str, engine_ids: list):
for engine_id in engine_ids:
import json
async def get_engine_with_ratios(gen_type: str, engines: list):
for engine in engines:
result = await db.execute(
select(CreditRatio)
.where(CreditRatio.gen_type == gen_type)
.where(CreditRatio.model_config_id == engine_id)
.where(CreditRatio.model_config_id == engine.id)
)
ratios = result.scalars().all()
if ratios:
return [CreditRatioOut.model_validate(r) for r in ratios]
return []
ratios_out = [CreditRatioOut.model_validate(r) for r in ratios]
engine_info = {
"id": engine.id,
"name": engine.name,
"provider": engine.provider,
"ratios": ratios_out,
}
if gen_type == "video":
try:
supported_ratios = json.loads(engine.supported_ratios) if engine.supported_ratios else []
except Exception:
supported_ratios = []
try:
supported_resolutions = json.loads(engine.supported_resolutions) if engine.supported_resolutions else []
except Exception:
supported_resolutions = []
try:
supported_durations = json.loads(engine.supported_durations) if engine.supported_durations else []
except Exception:
supported_durations = []
engine_info.update({
"supported_ratios": supported_ratios,
"supported_resolutions": supported_resolutions,
"supported_durations": supported_durations,
"max_duration": engine.max_duration,
"max_image_count": engine.max_image_count,
"max_video_count": engine.max_video_count,
})
return engine_info
return None
video_engines_result = await db.execute(
select(VideoEngine.id)
select(VideoEngine)
.where(VideoEngine.is_active == True)
.order_by(VideoEngine.priority.desc())
)
video_engine_ids = video_engines_result.scalars().all()
video_engines = video_engines_result.scalars().all()
image_engines_result = await db.execute(
select(ImageEngine.id)
select(ImageEngine)
.where(ImageEngine.is_active == True)
.order_by(ImageEngine.priority.desc())
)
image_engine_ids = image_engines_result.scalars().all()
image_engines = image_engines_result.scalars().all()
grouped = {}
video_ratios = await get_ratios_for_engine_type("video", video_engine_ids)
if video_ratios:
grouped["video"] = video_ratios
image_ratios = await get_ratios_for_engine_type("image", image_engine_ids)
if image_ratios:
grouped["image"] = image_ratios
video_data = await get_engine_with_ratios("video", video_engines)
if video_data:
grouped["video"] = video_data
image_data = await get_engine_with_ratios("image", image_engines)
if image_data:
grouped["image"] = image_data
return grouped
@@ -49,5 +49,7 @@ async def list_active_engines(
"supported_ratios": ratios,
"supported_resolutions": resolutions,
"supported_durations": durations,
"max_image_count": e.max_image_count,
"max_video_count": e.max_video_count,
})
return {"items": items}
+2
View File
@@ -17,6 +17,8 @@ class VideoEngine(Base, TimestampMixin):
supported_resolutions: Mapped[str] = mapped_column(String(256), default='["480p","720p","1080p"]')
supported_durations: Mapped[str] = mapped_column(String(256), nullable=True, default='[4,5,6,7,8,9,10,11,12,13,14,15]')
max_duration: Mapped[int] = mapped_column(Integer, default=15)
max_image_count: Mapped[int] = mapped_column(Integer, default=5)
max_video_count: Mapped[int] = mapped_column(Integer, default=2)
generate_url: Mapped[str | None] = mapped_column(String(512), nullable=True, default="")
query_url: Mapped[str | None] = mapped_column(String(512), nullable=True, default="")
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
@@ -13,6 +13,8 @@ class VideoEngineCreate(BaseModel):
supported_resolutions: str = Field(default='["480p","720p","1080p"]')
supported_durations: str = Field(default='[4,5,6,7,8,9,10,11,12,13,14,15]')
max_duration: int = Field(default=15)
max_image_count: int = Field(default=5)
max_video_count: int = Field(default=2)
generate_url: str = Field(default="", max_length=512)
query_url: str = Field(default="", max_length=512)
is_active: bool = True
@@ -33,6 +35,8 @@ class VideoEnginePublic(BaseModel):
supported_ratios: list[str] = []
supported_resolutions: list[str] = []
supported_durations: list[int] = []
max_image_count: int = 5
max_video_count: int = 2
class VideoEngineListResponse(BaseModel):