diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 22eb3a6..1652fc2 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -173,8 +173,13 @@ export default async function RootLayout({ } // 将运行时配置注入到全局 window 对象,供客户端在运行时读取 + const runtimeStorageType = process.env.NEXT_PUBLIC_STORAGE_TYPE || 'localstorage'; + const isCloudflare = process.env.CF_PAGES === '1' || process.env.BUILD_TARGET === 'cloudflare'; + const displayStorageType = runtimeStorageType === 'd1' && !isCloudflare ? 'sqlite' : runtimeStorageType; + const runtimeConfig = { - STORAGE_TYPE: process.env.NEXT_PUBLIC_STORAGE_TYPE || 'localstorage', + STORAGE_TYPE: runtimeStorageType, + DISPLAY_STORAGE_TYPE: displayStorageType, DOUBAN_PROXY_TYPE: doubanProxyType, DOUBAN_PROXY: doubanProxy, DOUBAN_IMAGE_PROXY_TYPE: doubanImageProxyType, diff --git a/src/components/UserMenu.tsx b/src/components/UserMenu.tsx index 104694a..c52dda5 100644 --- a/src/components/UserMenu.tsx +++ b/src/components/UserMenu.tsx @@ -73,6 +73,7 @@ export const UserMenu: React.FC = () => { const [isDownloadManagementOpen, setIsDownloadManagementOpen] = useState(false); const [authInfo, setAuthInfo] = useState(null); const [storageType, setStorageType] = useState('localstorage'); + const [displayStorageType, setDisplayStorageType] = useState('localstorage'); const [mounted, setMounted] = useState(false); const [unreadCount, setUnreadCount] = useState(0); @@ -413,9 +414,11 @@ export const UserMenu: React.FC = () => { const auth = getAuthInfoFromBrowserCookie(); setAuthInfo(auth); - const type = - (window as any).RUNTIME_CONFIG?.STORAGE_TYPE || 'localstorage'; + const runtimeConfig = (window as any).RUNTIME_CONFIG || {}; + const type = runtimeConfig.STORAGE_TYPE || 'localstorage'; + const displayType = runtimeConfig.DISPLAY_STORAGE_TYPE || type; setStorageType(type); + setDisplayStorageType(displayType); } }, []); @@ -1498,7 +1501,7 @@ export const UserMenu: React.FC = () => {
数据存储: - {storageType === 'localstorage' ? '本地' : storageType} + {displayStorageType === 'localstorage' ? '本地' : displayStorageType}