diff --git a/apps/common/middleware/chat_headers_middleware.py b/apps/common/middleware/chat_headers_middleware.py index 904ab229892..dc35dbdb214 100644 --- a/apps/common/middleware/chat_headers_middleware.py +++ b/apps/common/middleware/chat_headers_middleware.py @@ -1,11 +1,12 @@ # coding=utf-8 """ - @project: maxkb - @Author:虎 - @file: static_headers_middleware.py - @date:2024/3/13 18:26 - @desc: +@project: maxkb +@Author:虎 +@file: static_headers_middleware.py +@date:2024/3/13 18:26 +@desc: """ + from django.utils.deprecation import MiddlewareMixin from common.cache_data.application_access_token_cache import get_application_access_token @@ -17,23 +18,26 @@ class ChatHeadersMiddleware(MiddlewareMixin): def process_response(self, request, response): if request.path.startswith(CONFIG.get_chat_path()) and not request.path.startswith( - CONFIG.get_chat_path() + '/api'): - access_token = request.path.replace(CONFIG.get_chat_path() + '/', '') - if access_token.__contains__('/') or access_token == 'undefined': + CONFIG.get_chat_path() + "/api" + ): + access_token = request.path.replace(CONFIG.get_chat_path() + "/", "") + if access_token.__contains__("/") or access_token == "undefined": return response application_access_token = get_application_access_token(access_token, True) if application_access_token is not None: - white_active = application_access_token.get('white_active', False) - white_list = application_access_token.get('white_list', []) - application_icon = escape(application_access_token.get('application_icon') or '') - application_name = escape(application_access_token.get('application_name') or '') + white_active = application_access_token.get("white_active", False) + white_list = application_access_token.get("white_list", []) + application_icon = escape(application_access_token.get("application_icon") or "") + application_name = escape(application_access_token.get("application_name") or "") if white_active: # 添加自定义的响应头 - response[ - 'Content-Security-Policy'] = f'frame-ancestors {" ".join(white_list)}' - response.content = (response.content.decode('utf-8').replace( - '', - f'') - .replace('MaxKB', f'{application_name}').encode( - "utf-8")) + response["Content-Security-Policy"] = f"frame-ancestors {' '.join(white_list)}" + response.content = ( + response.content.decode("utf-8") + .replace( + '', f'' + ) + .replace("MaxKB", f"{application_name}") + .encode("utf-8") + ) return response diff --git a/ui/src/router/ROUTE_README.md b/ui/src/router/ROUTE_README.md index d86595d77ad..aa3a2983642 100644 --- a/ui/src/router/ROUTE_README.md +++ b/ui/src/router/ROUTE_README.md @@ -138,6 +138,9 @@ Chat 导航守卫(`chat/index.ts`): 当前场景只在放行前切换,请求层直接读取 `auth.token`,导航未完成时不会带上目标场景的 token。 +Chat Router 不根据 `route.meta.title` 更新浏览器标题:单应用对话页的标题和图标由后端 +`ChatHeadersMiddleware` 替换为应用名称与应用图标,前端不得覆盖。 + 接口返回 401(`/auth/` 认证接口除外)时,请求层调用 `reauthenticate()`:将当前场景的 token 标记为失效(Store 中清除,本地存储保留),并以 `force: true` 重新导航到当前地址,由守卫重新匿名认证或跳转登录页。同一时间只处理一次。 diff --git a/ui/src/router/chat/index.ts b/ui/src/router/chat/index.ts index c0138297302..e5c2dfc6258 100644 --- a/ui/src/router/chat/index.ts +++ b/ui/src/router/chat/index.ts @@ -85,10 +85,6 @@ chatRouter.beforeEach(async (to) => { return getLoginRoute(scope, to) }) -chatRouter.afterEach((to) => { - document.title = to.meta.title ? `${to.meta.title} - MaxKB` : 'MaxKB' -}) - let isReauthenticating = false /**