127 lines
3.9 KiB
Python
127 lines
3.9 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.dependencies import get_admin_user, get_db
|
|
from app.models.user import User
|
|
from app.schemas.video_prompt_schema_config import (
|
|
VideoPromptSchemaConfigImportRequest,
|
|
VideoPromptSchemaConfigOut,
|
|
VideoPromptSchemaConfigSaveRequest,
|
|
VideoPromptSchemaExportOut,
|
|
VideoPromptSchemaPreviewOut,
|
|
VideoPromptSchemaPreviewRequest,
|
|
)
|
|
from app.services.video_prompt_schema_config_service import (
|
|
export_video_prompt_schema_config,
|
|
get_video_prompt_schema_config,
|
|
import_video_prompt_schema_config,
|
|
preview_runtime_schema,
|
|
reset_video_prompt_schema_config,
|
|
save_video_prompt_schema_config,
|
|
)
|
|
from app.services.operation_log import log_operation
|
|
|
|
router = APIRouter(prefix="/admin/video-prompt-schema-config", tags=["admin-video-prompt-schema-config"])
|
|
|
|
|
|
@router.get("", response_model=VideoPromptSchemaConfigOut, summary="获取视频提词 Schema 配置")
|
|
async def get_config(
|
|
admin: User = Depends(get_admin_user),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
_ = admin
|
|
return await get_video_prompt_schema_config(db)
|
|
|
|
|
|
@router.put("", response_model=VideoPromptSchemaConfigOut, summary="保存视频提词 Schema 配置")
|
|
async def save_config(
|
|
req: VideoPromptSchemaConfigSaveRequest,
|
|
admin: User = Depends(get_admin_user),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
result = await save_video_prompt_schema_config(db, data=req.data, is_enabled=req.is_enabled)
|
|
await log_operation(
|
|
db,
|
|
admin.id,
|
|
admin.username,
|
|
"保存视频提词 Schema 配置",
|
|
"PUT",
|
|
"/admin/video-prompt-schema-config",
|
|
detail=json.dumps(
|
|
{
|
|
"is_enabled": req.is_enabled,
|
|
},
|
|
ensure_ascii=False,
|
|
),
|
|
)
|
|
return result
|
|
|
|
|
|
@router.post("/reset-default", response_model=VideoPromptSchemaConfigOut, summary="恢复默认视频提词 Schema 配置")
|
|
async def reset_default(
|
|
admin: User = Depends(get_admin_user),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
result = await reset_video_prompt_schema_config(db)
|
|
await log_operation(
|
|
db,
|
|
admin.id,
|
|
admin.username,
|
|
"恢复默认视频提词 Schema 配置",
|
|
"POST",
|
|
"/admin/video-prompt-schema-config/reset-default",
|
|
detail=json.dumps(
|
|
{
|
|
"reset_to_default": True,
|
|
},
|
|
ensure_ascii=False,
|
|
),
|
|
)
|
|
return result
|
|
|
|
|
|
@router.get("/export", response_model=VideoPromptSchemaExportOut, summary="导出视频提词 Schema 配置")
|
|
async def export_config(
|
|
admin: User = Depends(get_admin_user),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
_ = admin
|
|
return await export_video_prompt_schema_config(db)
|
|
|
|
|
|
@router.post("/import", response_model=VideoPromptSchemaConfigOut, summary="导入视频提词 Schema 配置")
|
|
async def import_config(
|
|
req: VideoPromptSchemaConfigImportRequest,
|
|
admin: User = Depends(get_admin_user),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
result = await import_video_prompt_schema_config(db, data=req.data, is_enabled=req.is_enabled)
|
|
await log_operation(
|
|
db,
|
|
admin.id,
|
|
admin.username,
|
|
"导入视频提词 Schema 配置",
|
|
"POST",
|
|
"/admin/video-prompt-schema-config/import",
|
|
detail=json.dumps(
|
|
{
|
|
"is_enabled": req.is_enabled,
|
|
},
|
|
ensure_ascii=False,
|
|
),
|
|
)
|
|
return result
|
|
|
|
|
|
@router.post("/preview", response_model=VideoPromptSchemaPreviewOut, summary="预览视频提词运行时 Schema")
|
|
async def preview_config(
|
|
req: VideoPromptSchemaPreviewRequest,
|
|
admin: User = Depends(get_admin_user),
|
|
):
|
|
_ = admin
|
|
return preview_runtime_schema(data=req.data, is_enabled=req.is_enabled, video_config=req.to_video_config())
|