1.mirror_to_ai_chat: _uuid→uuid(NameError被except吞了, 对话从未同步到webclaw) 2.im_bot_admin加_beijing_now并替换5处datetime.now()(容器UTC存naive时间前端按+08:00展示错位8小时)
This commit is contained in:
1 parent
f975672b0e
commit
ab11283d92
2 files changed
+14
-6
No files matched your search
@@ -14,7 +14,15 @@ import hmac
|
||||
import time
|
||||
import threading
|
||||
import requests
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
# #976 全平台统一使用北京时间(容器 UTC,前端按 +08:00 展示)
|
||||
_TZ_BEIJING = timezone(timedelta(hours=8))
|
||||
|
||||
|
||||
def _beijing_now():
|
||||
"""返回 naive 北京时间(容器 UTC 时区下,需显式转)"""
|
||||
return datetime.now(_TZ_BEIJING).replace(tzinfo=None)
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
@@ -773,13 +781,13 @@ async def wechat_qrcode_status(qrcode: str = Query(...), user=Depends(get_curren
|
||||
(bot_token, ilink_bot_id, baseurl, status, connected_at, created_at, updated_at)
|
||||
VALUES (:bot_token, :ilink_bot_id, :baseurl, 'connected', :connected_at, :created_at, :updated_at)"""),
|
||||
{"bot_token": bot_token, "ilink_bot_id": ilink_bot_id, "baseurl": baseurl,
|
||||
"connected_at": datetime.now(), "created_at": datetime.now(), "updated_at": datetime.now()})
|
||||
"connected_at": _beijing_now(), "created_at": _beijing_now(), "updated_at": _beijing_now()})
|
||||
else:
|
||||
_execute_raw(db, text("""UPDATE im_bot_wechat_account SET
|
||||
bot_token=:bot_token, ilink_bot_id=:ilink_bot_id, baseurl=:baseurl,
|
||||
status='connected', connected_at=:connected_at, updated_at=:updated_at WHERE id=:id"""),
|
||||
{"bot_token": bot_token, "ilink_bot_id": ilink_bot_id, "baseurl": baseurl,
|
||||
"connected_at": datetime.now(), "updated_at": datetime.now(), "id": _row_to_dict(row)["id"]})
|
||||
"connected_at": _beijing_now(), "updated_at": _beijing_now(), "id": _row_to_dict(row)["id"]})
|
||||
row = _wechat_row(db)
|
||||
aid = _row_to_dict(row)["id"] if row else 1
|
||||
_start_wechat_receiver(aid)
|
||||
@@ -821,7 +829,7 @@ async def wechat_disconnect(user=Depends(get_current_user)):
|
||||
row = _wechat_row(db)
|
||||
if row:
|
||||
_execute_raw(db, text("UPDATE im_bot_wechat_account SET bot_token=NULL, status='disconnected', updated_at=:updated_at WHERE id=:id"),
|
||||
{"updated_at": datetime.now(), "id": _row_to_dict(row)["id"]})
|
||||
{"updated_at": _beijing_now(), "id": _row_to_dict(row)["id"]})
|
||||
return {"success": True, "message": "已断开个人微信连接"}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@@ -551,7 +551,7 @@ def _get_or_create_wechat_conv(db: Session, user_id: str) -> str:
|
||||
), {"uid": user_id})
|
||||
if rows:
|
||||
return _row_to_dict(rows[0])["id"]
|
||||
cid = str(_uuid.uuid4())
|
||||
cid = str(uuid.uuid4())
|
||||
now = _beijing_now()
|
||||
_execute_raw(db, text(
|
||||
"INSERT INTO conversations "
|
||||
@@ -566,7 +566,7 @@ def _append_ai_message(db: Session, conv_id: str, role: str, content: str, creat
|
||||
"INSERT INTO messages (id, conversation_id, role, content, token_used, created_at) "
|
||||
"VALUES (:id, :cid, :role, :content, 0, :c)"
|
||||
), {
|
||||
"id": str(_uuid.uuid4()), "cid": conv_id, "role": role,
|
||||
"id": str(uuid.uuid4()), "cid": conv_id, "role": role,
|
||||
"content": content, "c": created or _beijing_now(),
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user