From 299c508f27bac05f0f18517bf8e02444409e1f61 Mon Sep 17 00:00:00 2001 From: yangdx Date: Sat, 5 Apr 2025 02:24:23 +0800 Subject: [PATCH] Fix webtitle display problem --- lightrag/api/lightrag_server.py | 2 ++ lightrag_webui/src/App.tsx | 8 +++++--- lightrag_webui/src/api/lightrag.ts | 23 ----------------------- lightrag_webui/src/features/LoginPage.tsx | 4 ++-- lightrag_webui/src/stores/state.ts | 6 ++++++ 5 files changed, 15 insertions(+), 28 deletions(-) diff --git a/lightrag/api/lightrag_server.py b/lightrag/api/lightrag_server.py index 9f1e6e8a..84636bde 100644 --- a/lightrag/api/lightrag_server.py +++ b/lightrag/api/lightrag_server.py @@ -436,6 +436,8 @@ def create_app(args): "auth_mode": "enabled", "core_version": core_version, "api_version": __api_version__, + "webui_title": webui_title, + "webui_description": webui_description, } @app.get("/health", dependencies=[Depends(combined_auth)]) diff --git a/lightrag_webui/src/App.tsx b/lightrag_webui/src/App.tsx index 487ca2e8..eba7cfc8 100644 --- a/lightrag_webui/src/App.tsx +++ b/lightrag_webui/src/App.tsx @@ -63,14 +63,16 @@ function App() { try { const status = await getAuthStatus(); - if (status.core_version || status.api_version) { + if (status.core_version || status.api_version || status.webui_title || status.webui_description) { const isGuestMode = status.auth_mode === 'disabled' || useAuthStore.getState().isGuestMode; - // Update version info while maintaining login state + // Update version info and webui title while maintaining login state useAuthStore.getState().login( token, isGuestMode, status.core_version, - status.api_version + status.api_version, + status.webui_title || null, + status.webui_description || null ); // Set flag to indicate version info has been checked diff --git a/lightrag_webui/src/api/lightrag.ts b/lightrag_webui/src/api/lightrag.ts index bf208f8b..bd49f7dc 100644 --- a/lightrag_webui/src/api/lightrag.ts +++ b/lightrag_webui/src/api/lightrag.ts @@ -3,7 +3,6 @@ import { backendBaseUrl } from '@/lib/constants' import { errorMessage } from '@/lib/utils' import { useSettingsStore } from '@/stores/settings' import { navigationService } from '@/services/navigation' -import { useAuthStore } from '@/stores/state' // Types export type LightragNodeType = { @@ -426,26 +425,12 @@ export const getAuthStatus = async (): Promise => { // For unconfigured auth, ensure we have an access token if (!response.data.auth_configured) { if (response.data.access_token && typeof response.data.access_token === 'string') { - // Update custom title if available - if ('webui_title' in response.data || 'webui_description' in response.data) { - useAuthStore.getState().setCustomTitle( - 'webui_title' in response.data ? (response.data.webui_title ?? null) : null, - 'webui_description' in response.data ? (response.data.webui_description ?? null) : null - ); - } return response.data; } else { console.warn('Auth not configured but no valid access token provided'); } } else { // For configured auth, just return the data - // Update custom title if available - if ('webui_title' in response.data || 'webui_description' in response.data) { - useAuthStore.getState().setCustomTitle( - 'webui_title' in response.data ? (response.data.webui_title ?? null) : null, - 'webui_description' in response.data ? (response.data.webui_description ?? null) : null - ); - } return response.data; } } @@ -484,13 +469,5 @@ export const loginToServer = async (username: string, password: string): Promise } }); - // Update custom title if available - if ('webui_title' in response.data || 'webui_description' in response.data) { - useAuthStore.getState().setCustomTitle( - 'webui_title' in response.data ? (response.data.webui_title ?? null) : null, - 'webui_description' in response.data ? (response.data.webui_description ?? null) : null - ); - } - return response.data; } diff --git a/lightrag_webui/src/features/LoginPage.tsx b/lightrag_webui/src/features/LoginPage.tsx index 847a4c9e..fc60370c 100644 --- a/lightrag_webui/src/features/LoginPage.tsx +++ b/lightrag_webui/src/features/LoginPage.tsx @@ -51,7 +51,7 @@ const LoginPage = () => { if (!status.auth_configured && status.access_token) { // If auth is not configured, use the guest token and redirect - login(status.access_token, true, status.core_version, status.api_version) + login(status.access_token, true, status.core_version, status.api_version, status.webui_title || null, status.webui_description || null) if (status.message) { toast.info(status.message) } @@ -96,7 +96,7 @@ const LoginPage = () => { // Check authentication mode const isGuestMode = response.auth_mode === 'disabled' - login(response.access_token, isGuestMode, response.core_version, response.api_version) + login(response.access_token, isGuestMode, response.core_version, response.api_version, response.webui_title || null, response.webui_description || null) // Set session flag for version check if (response.core_version || response.api_version) { diff --git a/lightrag_webui/src/stores/state.ts b/lightrag_webui/src/stores/state.ts index 785af199..2050a46a 100644 --- a/lightrag_webui/src/stores/state.ts +++ b/lightrag_webui/src/stores/state.ts @@ -171,11 +171,17 @@ export const useAuthStore = create(set => { if (apiVersion) { localStorage.setItem('LIGHTRAG-API-VERSION', apiVersion); } + if (webuiTitle) { localStorage.setItem('LIGHTRAG-WEBUI-TITLE', webuiTitle); + } else { + localStorage.removeItem('LIGHTRAG-WEBUI-TITLE'); } + if (webuiDescription) { localStorage.setItem('LIGHTRAG-WEBUI-DESCRIPTION', webuiDescription); + } else { + localStorage.removeItem('LIGHTRAG-WEBUI-DESCRIPTION'); } const username = getUsernameFromToken(token);