生成项目任务/chat任务软删|生成资源管控回收|生成资源token验签API预处理

This commit is contained in:
2026-06-01 11:10:09 +08:00
parent edef601f7c
commit dfbf51b5c0
26 changed files with 1296 additions and 63 deletions
+16 -7
View File
@@ -42,6 +42,7 @@ from app.services.credits import add_credits, deduct_credits
from app.services.notification import create_notification
from app.services.auth import hash_password, verify_password
from app.services.operation_log import log_operation
from app.services.resource_signed_url_service import build_resource_signed_url
from app.utils.id_gen import generate_id
from app.schemas.generation import GenerationType, ASPECT_RATIOS, RESOLUTIONS
@@ -884,9 +885,9 @@ async def get_stats(
total_users = (await db.execute(
select(func.count(User.id)).where(User.user_type == "frontend")
)).scalar() or 0
total_projects = (await db.execute(select(func.count(Project.id)))).scalar() or 0
total_projects = (await db.execute(select(func.count(Project.id)).where(Project.deleted_at.is_(None)))).scalar() or 0
total_generations = (
await db.execute(select(func.count(GenerationRecord.id)))
await db.execute(select(func.count(GenerationRecord.id)).where(GenerationRecord.deleted_at.is_(None)))
).scalar() or 0
total_revenue = (
await db.execute(
@@ -973,6 +974,7 @@ async def admin_list_generation_records(
select(GenerationRecord, User.username, Project.name)
.join(User, GenerationRecord.user_id == User.id)
.join(Project, GenerationRecord.project_id == Project.id)
.where(GenerationRecord.deleted_at.is_(None), Project.deleted_at.is_(None))
.order_by(GenerationRecord.created_at.desc())
)
if user_id:
@@ -981,7 +983,7 @@ async def admin_list_generation_records(
query = query.where(GenerationRecord.status == status)
# Count total
count_query = select(func.count(GenerationRecord.id))
count_query = select(func.count(GenerationRecord.id)).where(GenerationRecord.deleted_at.is_(None))
if user_id:
count_query = count_query.where(GenerationRecord.user_id == user_id)
if status:
@@ -1015,7 +1017,7 @@ async def admin_list_generation_records(
"aspect_ratio": record.aspect_ratio,
"resolution": record.resolution,
"status": record.status,
"video_url": record.video_url,
"video_url": build_resource_signed_url(record.video_url) if record.video_url else '',
"references": refs,
"credits_cost": record.credits_cost or 0,
"text_credits_cost": record.text_credits_cost or 0,
@@ -1028,7 +1030,7 @@ async def admin_list_generation_records(
# append img param
"gen_type": record.gen_type,
"image_size": record.image_size or '',
"image_url": record.image_url or '',
"image_url": build_resource_signed_url(record.image_url) if record.image_url else '',
"image_tokens_used": record.image_tokens_used or 0,
"image_proportion": record.image_proportion or '',
"image_px": record.image_px or '',
@@ -1046,7 +1048,10 @@ async def admin_update_generation_status(
):
"""Admin update generation record status (e.g., confirm/reject)."""
result = await db.execute(
select(GenerationRecord).where(GenerationRecord.id == record_id)
select(GenerationRecord).where(
GenerationRecord.id == record_id,
GenerationRecord.deleted_at.is_(None),
)
)
record = result.scalar_one_or_none()
if not record:
@@ -1080,7 +1085,11 @@ async def admin_generate_video(
result = await db.execute(
select(GenerationRecord, Project.name)
.join(Project, GenerationRecord.project_id == Project.id)
.where(GenerationRecord.id == record_id)
.where(
GenerationRecord.id == record_id,
GenerationRecord.deleted_at.is_(None),
Project.deleted_at.is_(None),
)
)
row = result.first()
if not row: