mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-09-05 07:36:53 +08:00
fix(AI,Web): Optimize the experience
This commit is contained in:
@@ -17,13 +17,27 @@ public class AiService(IHttpClientFactory httpClientFactory, IConfigService conf
|
||||
string apiKey = configService["AI:ApiKey"];
|
||||
string baseUrl = configService["AI:ApiEndpoint"];
|
||||
|
||||
if (string.IsNullOrWhiteSpace(apiKey))
|
||||
{
|
||||
throw new InvalidOperationException("AI API Key 未配置或为空。请检查配置文件中的 AI:ApiKey 设置。");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(baseUrl))
|
||||
{
|
||||
throw new InvalidOperationException("AI API Endpoint 未配置或为空。请检查配置文件中的 AI:ApiEndpoint 设置。");
|
||||
}
|
||||
|
||||
if (!Uri.TryCreate(baseUrl, UriKind.Absolute, out Uri? validUri))
|
||||
{
|
||||
throw new InvalidOperationException($"AI API Endpoint 格式无效: {baseUrl}。请提供有效的 URL。");
|
||||
}
|
||||
|
||||
if (_httpClient == null || _currentApiKey != apiKey || _currentBaseUrl != baseUrl)
|
||||
{
|
||||
_httpClient?.Dispose();
|
||||
_httpClient = httpClientFactory.CreateClient();
|
||||
_httpClient.BaseAddress = new Uri(baseUrl);
|
||||
_httpClient.BaseAddress = validUri;
|
||||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
|
||||
|
||||
// 更新当前配置记录
|
||||
_currentApiKey = apiKey;
|
||||
_currentBaseUrl = baseUrl;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { Link, useNavigate, useLocation } from 'react-router';
|
||||
import { useAuth } from '../../auth/AuthContext';
|
||||
import { getMainRoutes, getAdminRoutes, type RouteConfig } from '../../routes';
|
||||
import UserAvatar from '../../components/UserAvatar';
|
||||
import { UserRole } from '../../api/types';
|
||||
import { UserRole } from '../../api';
|
||||
import SearchDialog from '../../components/search/SearchDialog';
|
||||
import useIsMobile from '../../hooks/useIsMobile';
|
||||
|
||||
|
||||
@@ -181,7 +181,7 @@ const Sidebar: React.FC<SidebarProps> = ({ collapsed, isMobile = false, onClose,
|
||||
height: isMobile ? '56px' : '64px',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: collapsed ? 'center' : 'flex-start',
|
||||
justifyContent: 'center',
|
||||
padding: collapsed ? '0' : '0 20px',
|
||||
color: '#001529',
|
||||
fontWeight: 'bold',
|
||||
|
||||
Reference in New Issue
Block a user