- 4张数据表: posts/comments/likes/downloads - 5种媒体类型: music/mtv/short_video/long_video/ktv - 社交功能: 点赞(toggle)、评论(嵌套回复) - KTV付费下载: 购买记录、下载计数 - 11个dspy API端点 - 3个CRUD管理界面(posts/comments/downloads) - Feed流(类型筛选+分页)、作品详情(浏览计数+点赞状态) - load_path.py RBAC权限注册 - 符合module/db-table/crud三规范
36 lines
1.3 KiB
Plaintext
36 lines
1.3 KiB
Plaintext
try:
|
|
db = DBPools()
|
|
media_type = params_kw.get('media_type', '')
|
|
page = int(params_kw.get('page', 1))
|
|
page_size = int(params_kw.get('page_size', 20))
|
|
offset = (page - 1) * page_size
|
|
|
|
where = "WHERE status = '1'"
|
|
bindparams = {}
|
|
if media_type:
|
|
where += " AND media_type = ${media_type}$"
|
|
bindparams['media_type'] = media_type
|
|
|
|
async with db.sqlorContext('sage') as sor:
|
|
total_r = await sor.sqlExe(
|
|
f"SELECT COUNT(*) as cnt FROM showcase_posts {where}", bindparams
|
|
)
|
|
total = total_r[0]['cnt'] if total_r else 0
|
|
|
|
posts = await sor.sqlExe(
|
|
f"""SELECT id, author_id, author_name, title, description, media_type,
|
|
content_url, thumbnail_url, duration, tags, category,
|
|
like_count, comment_count, view_count, download_count,
|
|
is_featured, price, created_at
|
|
FROM showcase_posts {where}
|
|
ORDER BY created_at DESC
|
|
LIMIT {page_size} OFFSET {offset}""",
|
|
bindparams
|
|
)
|
|
return json.dumps({
|
|
"status": "ok", "data": list(posts),
|
|
"total": total, "page": page, "page_size": page_size
|
|
}, ensure_ascii=False)
|
|
except Exception as e:
|
|
return json.dumps({"status": "error", "data": [], "message": str(e)}, ensure_ascii=False)
|