- 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三规范
42 lines
1.6 KiB
Plaintext
42 lines
1.6 KiB
Plaintext
try:
|
|
db = DBPools()
|
|
post_id = params_kw.get('post_id', '')
|
|
user_id = await get_user()
|
|
|
|
async with db.sqlorContext('sage') as sor:
|
|
# 获取作品详情
|
|
posts = await sor.R('showcase_posts', {"id": post_id})
|
|
if not posts:
|
|
return json.dumps({"status": "error", "message": "作品不存在"}, ensure_ascii=False)
|
|
post = dict(posts[0])
|
|
|
|
# 增加浏览计数
|
|
new_view = (post.get('view_count', 0) or 0) + 1
|
|
await sor.U('showcase_posts', {"id": post_id, "view_count": new_view})
|
|
post['view_count'] = new_view
|
|
|
|
# 检查当前用户是否已点赞
|
|
liked = await sor.sqlExe(
|
|
"SELECT id FROM showcase_likes WHERE post_id = ${post_id}$ AND user_id = ${user_id}$",
|
|
{"post_id": post_id, "user_id": user_id}
|
|
)
|
|
post['is_liked'] = len(liked) > 0
|
|
|
|
# 检查是否已购买(付费作品)
|
|
if float(post.get('price', 0)) > 0:
|
|
bought = await sor.sqlExe(
|
|
"SELECT id FROM showcase_downloads WHERE post_id = ${post_id}$ AND user_id = ${user_id}$ AND payment_status = '1'",
|
|
{"post_id": post_id, "user_id": user_id}
|
|
)
|
|
post['is_purchased'] = len(bought) > 0
|
|
else:
|
|
post['is_purchased'] = True
|
|
|
|
# 移除敏感字段
|
|
post.pop('model_input', None)
|
|
post.pop('model_output', None)
|
|
|
|
return json.dumps({"status": "ok", "data": post}, ensure_ascii=False)
|
|
except Exception as e:
|
|
return json.dumps({"status": "error", "message": str(e)}, ensure_ascii=False)
|