Merge branch 'main' of https://gitee.com/wg123/video-gen
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.dependencies import get_db, get_current_user
|
||||
from app.models.user import User
|
||||
from app.models.credit_ratio import CreditRatio
|
||||
from app.models.video_engine import VideoEngine
|
||||
from app.models.image_engine import ImageEngine
|
||||
from app.schemas.credit import CreditBalanceOut, CreditRecordOut
|
||||
from app.schemas.credit_ratio import CreditRatioOut
|
||||
from app.services.credits import get_records
|
||||
from sqlalchemy import select
|
||||
|
||||
router = APIRouter(prefix="/credits", tags=["credits"])
|
||||
|
||||
@@ -29,13 +31,40 @@ async def get_credit_ratios(
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
result = await db.execute(select(CreditRatio))
|
||||
ratios = result.scalars().all()
|
||||
async def get_ratios_for_engine_type(gen_type: str, engine_ids: list):
|
||||
for engine_id in engine_ids:
|
||||
result = await db.execute(
|
||||
select(CreditRatio)
|
||||
.where(CreditRatio.gen_type == gen_type)
|
||||
.where(CreditRatio.model_config_id == engine_id)
|
||||
)
|
||||
ratios = result.scalars().all()
|
||||
if ratios:
|
||||
return [CreditRatioOut.model_validate(r) for r in ratios]
|
||||
return []
|
||||
|
||||
video_engines_result = await db.execute(
|
||||
select(VideoEngine.id)
|
||||
.where(VideoEngine.is_active == True)
|
||||
.order_by(VideoEngine.priority.desc())
|
||||
)
|
||||
video_engine_ids = video_engines_result.scalars().all()
|
||||
|
||||
image_engines_result = await db.execute(
|
||||
select(ImageEngine.id)
|
||||
.where(ImageEngine.is_active == True)
|
||||
.order_by(ImageEngine.priority.desc())
|
||||
)
|
||||
image_engine_ids = image_engines_result.scalars().all()
|
||||
|
||||
grouped = {}
|
||||
for ratio in ratios:
|
||||
if ratio.gen_type not in grouped:
|
||||
grouped[ratio.gen_type] = []
|
||||
grouped[ratio.gen_type].append(CreditRatioOut.model_validate(ratio))
|
||||
|
||||
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
|
||||
|
||||
return grouped
|
||||
|
||||
@@ -30,7 +30,10 @@ async def list_active_industries(
|
||||
try:
|
||||
raw = json.loads(ind.skills)
|
||||
if isinstance(raw, list):
|
||||
skills = raw if raw and isinstance(raw[0], dict) else [{"key": s, "label": s} for s in raw]
|
||||
if raw and isinstance(raw[0], dict):
|
||||
skills = [s for s in raw if s.get("type") != "skill"]
|
||||
else:
|
||||
skills = [{"key": s, "label": s} for s in raw]
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
skills = []
|
||||
items.append({
|
||||
|
||||
Reference in New Issue
Block a user