fix: 修复web app 会话工作流 404问题会话列表

Co-authored-by: Cursor <github@npc0.com>
This commit is contained in:
npc0-hue
2026-02-25 17:08:02 +08:00
parent 10ec0eb953
commit bd856e988f
4 changed files with 48 additions and 7 deletions
@@ -7,6 +7,7 @@ data:
server { server {
listen 8080; listen 8080;
server_name localhost; server_name localhost;
absolute_redirect off;
#charset koi8-r; #charset koi8-r;
#access_log logs/host.access.log main; #access_log logs/host.access.log main;
+2 -2
View File
@@ -44,8 +44,8 @@ func Corn() {
} }
global.GVA_LOG.Info("【定时任务-每1分钟执行1次】同步用户列表任务,已启动!") global.GVA_LOG.Info("【定时任务-每1分钟执行1次】同步用户列表任务,已启动!")
// 每10分钟同步一次【应用使用分析数据】 // 一天同步一次~待改目前没啥用【应用使用分析数据】
if _, err := c.AddFunc("0 */10 * * * *", func() { if _, err := c.AddFunc("0 0 1 * * *", func() {
if global.GVA_DB == nil { if global.GVA_DB == nil {
global.GVA_LOG.Info("【定时任务-每6分钟执行1次】同步应用使用分析数据任务,数据库没有初始化,暂未开始同步") global.GVA_LOG.Info("【定时任务-每6分钟执行1次】同步应用使用分析数据任务,数据库没有初始化,暂未开始同步")
return return
@@ -1,6 +1,7 @@
server { server {
listen 8081; listen 8081;
server_name localhost; server_name localhost;
absolute_redirect off; # 使用相对重定向,避免暴露后端端口导致浏览器跳转到 :8080
#charset koi8-r; #charset koi8-r;
#access_log logs/host.access.log main; #access_log logs/host.access.log main;
+44 -5
View File
@@ -48,12 +48,29 @@ class ConversationService:
if not user: if not user:
return InfiniteScrollPagination(data=[], limit=limit, has_more=False) return InfiniteScrollPagination(data=[], limit=limit, has_more=False)
if isinstance(user, EndUser):
from_source = "api"
# Include conversations owned by this end_user or by this end_user's linked account (Web login).
user_filter: Any = Conversation.from_end_user_id == user.id
if getattr(user, "external_user_id", None):
user_filter = or_(user_filter, Conversation.from_account_id == user.external_user_id)
base_conditions = (
Conversation.is_deleted == False,
Conversation.app_id == app_model.id,
Conversation.from_source == from_source,
user_filter,
)
else:
base_conditions = (
Conversation.is_deleted == False,
Conversation.app_id == app_model.id,
Conversation.from_source == "console",
Conversation.from_end_user_id.is_(None),
Conversation.from_account_id == user.id,
)
stmt = select(Conversation).where( stmt = select(Conversation).where(
Conversation.is_deleted == False, *base_conditions,
Conversation.app_id == app_model.id,
Conversation.from_source == ("api" if isinstance(user, EndUser) else "console"),
Conversation.from_end_user_id == (user.id if isinstance(user, EndUser) else None),
Conversation.from_account_id == (user.id if isinstance(user, Account) else None),
or_(Conversation.invoke_from.is_(None), Conversation.invoke_from == invoke_from.value), or_(Conversation.invoke_from.is_(None), Conversation.invoke_from == invoke_from.value),
) )
# Check if include_ids is not None to apply filter # Check if include_ids is not None to apply filter
@@ -173,6 +190,28 @@ class ConversationService:
.first() .first()
) )
# extend start: 二开部分End - web app 会话列表,兼容 cookie 和 header 登录
# Web App: fallback when conversation was created with same end_user but lookup fails
# (e.g. cookie vs header passport, or session refresh). Allow access when either
# from_end_user_id matches or from_account_id matches end_user's linked account.
if not conversation and isinstance(user, EndUser):
fallback = (
db.session.query(Conversation)
.where(
Conversation.id == conversation_id,
Conversation.app_id == app_model.id,
Conversation.from_source == "api",
Conversation.is_deleted == False,
)
.first()
)
if fallback and (
fallback.from_end_user_id == user.id
or (getattr(user, "external_user_id", None) and fallback.from_account_id == user.external_user_id)
):
conversation = fallback
# extend end: 二开部分End - web app 会话列表,兼容 cookie 和 header 登录
if not conversation: if not conversation:
raise ConversationNotExistsError() raise ConversationNotExistsError()