chore: 更新Docker配置,优化路由
- 更新docker-compose.yml - 优化conversations.py、plans.py、quota.py、user.py、websocket.py Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -170,6 +170,18 @@ async def websocket_endpoint(
|
||||
text_message = message.get("data", {}).get("text", "")
|
||||
|
||||
if text_message:
|
||||
# 校验对话轮数配额
|
||||
from routers.quota import get_segment_count, check_can_send_message
|
||||
seg_count = await get_segment_count(user_id, db)
|
||||
can_send, quota_msg = check_can_send_message(user.subscription_type, seg_count)
|
||||
if not can_send:
|
||||
await manager.send_message(conversation_id, {
|
||||
"type": MessageType.ERROR,
|
||||
"data": {"message": quota_msg, "code": "QUOTA_EXCEEDED"},
|
||||
"timestamp": datetime.now(timezone.utc).isoformat()
|
||||
})
|
||||
continue
|
||||
|
||||
# 保存段落到数据库
|
||||
segment = Segment(
|
||||
id=str(uuid.uuid4()),
|
||||
@@ -199,6 +211,18 @@ async def websocket_endpoint(
|
||||
audio_duration = data.get("duration", 0)
|
||||
|
||||
if audio_base64:
|
||||
# 校验对话轮数配额
|
||||
from routers.quota import get_segment_count, check_can_send_message
|
||||
seg_count = await get_segment_count(user_id, db)
|
||||
can_send, quota_msg = check_can_send_message(user.subscription_type, seg_count)
|
||||
if not can_send:
|
||||
await manager.send_message(conversation_id, {
|
||||
"type": MessageType.ERROR,
|
||||
"data": {"message": quota_msg, "code": "QUOTA_EXCEEDED"},
|
||||
"timestamp": datetime.now(timezone.utc).isoformat()
|
||||
})
|
||||
continue
|
||||
|
||||
logger.info(f"收到音频消息,时长: {audio_duration}s")
|
||||
|
||||
try:
|
||||
@@ -427,7 +451,21 @@ async def process_conversation_segments(conversation_id: str, db: AsyncSession):
|
||||
# 没有未处理的段落,直接 flush 待处理任务
|
||||
await manager.background_runner.flush_pending(conversation.user_id)
|
||||
return
|
||||
|
||||
|
||||
# 免费版仅允许 1 个章节整理,提交前校验
|
||||
from database.models import User as UserModel
|
||||
from routers.quota import get_chapter_count, check_can_submit_organize
|
||||
user = await db.get(UserModel, conversation.user_id)
|
||||
if user:
|
||||
chapter_count = await get_chapter_count(user.id, db)
|
||||
can_submit, _ = check_can_submit_organize(user.subscription_type, chapter_count)
|
||||
if not can_submit:
|
||||
logger.info(
|
||||
f"用户 {user.id} 章节配额已用尽,跳过提交整理任务: conversation_id={conversation_id}"
|
||||
)
|
||||
await manager.background_runner.flush_pending(conversation.user_id)
|
||||
return
|
||||
|
||||
# 将未处理的段落直接提交到 Celery(不通过去抖)
|
||||
segment_ids = [seg.id for seg in segments]
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user