2023-04-22 20:39:27 +08:00
|
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"encoding/json"
|
|
|
|
|
|
"net/http"
|
2023-04-22 21:14:09 +08:00
|
|
|
|
"one-api/common"
|
|
|
|
|
|
"one-api/model"
|
2024-12-25 19:31:12 +08:00
|
|
|
|
"one-api/setting"
|
2025-06-14 00:40:29 +08:00
|
|
|
|
"one-api/setting/console_setting"
|
2025-03-11 22:00:31 +08:00
|
|
|
|
"one-api/setting/system_setting"
|
2023-04-22 20:39:27 +08:00
|
|
|
|
"strings"
|
2023-07-30 12:44:41 +08:00
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2023-04-22 20:39:27 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func GetOptions(c *gin.Context) {
|
|
|
|
|
|
var options []*model.Option
|
|
|
|
|
|
common.OptionMapRWMutex.Lock()
|
|
|
|
|
|
for k, v := range common.OptionMap {
|
2024-04-18 17:52:18 +08:00
|
|
|
|
if strings.HasSuffix(k, "Token") || strings.HasSuffix(k, "Secret") || strings.HasSuffix(k, "Key") {
|
2023-04-22 20:39:27 +08:00
|
|
|
|
continue
|
|
|
|
|
|
}
|
|
|
|
|
|
options = append(options, &model.Option{
|
|
|
|
|
|
Key: k,
|
|
|
|
|
|
Value: common.Interface2String(v),
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
common.OptionMapRWMutex.Unlock()
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
|
"success": true,
|
|
|
|
|
|
"message": "",
|
|
|
|
|
|
"data": options,
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func UpdateOption(c *gin.Context) {
|
|
|
|
|
|
var option model.Option
|
|
|
|
|
|
err := json.NewDecoder(c.Request.Body).Decode(&option)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
c.JSON(http.StatusBadRequest, gin.H{
|
|
|
|
|
|
"success": false,
|
|
|
|
|
|
"message": "无效的参数",
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
switch option.Key {
|
|
|
|
|
|
case "GitHubOAuthEnabled":
|
|
|
|
|
|
if option.Value == "true" && common.GitHubClientId == "" {
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
|
"success": false,
|
2023-10-03 14:19:03 +08:00
|
|
|
|
"message": "无法启用 GitHub OAuth,请先填入 GitHub Client Id 以及 GitHub Client Secret!",
|
2023-04-22 20:39:27 +08:00
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-03-11 22:00:31 +08:00
|
|
|
|
case "oidc.enabled":
|
2025-03-31 00:46:13 +08:00
|
|
|
|
if option.Value == "true" && system_setting.GetOIDCSettings().ClientId == "" {
|
2025-02-28 15:18:03 +08:00
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
|
"success": false,
|
|
|
|
|
|
"message": "无法启用 OIDC 登录,请先填入 OIDC Client Id 以及 OIDC Client Secret!",
|
|
|
|
|
|
})
|
2025-03-31 00:46:13 +08:00
|
|
|
|
return
|
2025-02-28 15:18:03 +08:00
|
|
|
|
}
|
2024-11-10 23:56:22 +08:00
|
|
|
|
case "LinuxDOOAuthEnabled":
|
|
|
|
|
|
if option.Value == "true" && common.LinuxDOClientId == "" {
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
|
"success": false,
|
|
|
|
|
|
"message": "无法启用 LinuxDO OAuth,请先填入 LinuxDO Client Id 以及 LinuxDO Client Secret!",
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2023-07-30 12:44:41 +08:00
|
|
|
|
case "EmailDomainRestrictionEnabled":
|
|
|
|
|
|
if option.Value == "true" && len(common.EmailDomainWhitelist) == 0 {
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
|
"success": false,
|
|
|
|
|
|
"message": "无法启用邮箱域名限制,请先填入限制的邮箱域名!",
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2023-04-22 20:39:27 +08:00
|
|
|
|
case "WeChatAuthEnabled":
|
|
|
|
|
|
if option.Value == "true" && common.WeChatServerAddress == "" {
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
|
"success": false,
|
|
|
|
|
|
"message": "无法启用微信登录,请先填入微信登录相关配置信息!",
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
case "TurnstileCheckEnabled":
|
|
|
|
|
|
if option.Value == "true" && common.TurnstileSiteKey == "" {
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
|
"success": false,
|
|
|
|
|
|
"message": "无法启用 Turnstile 校验,请先填入 Turnstile 校验相关配置信息!",
|
|
|
|
|
|
})
|
2025-03-31 00:46:13 +08:00
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
case "TelegramOAuthEnabled":
|
|
|
|
|
|
if option.Value == "true" && common.TelegramBotToken == "" {
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
|
"success": false,
|
|
|
|
|
|
"message": "无法启用 Telegram OAuth,请先填入 Telegram Bot Token!",
|
|
|
|
|
|
})
|
2023-04-22 20:39:27 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2024-09-20 18:09:40 +08:00
|
|
|
|
case "GroupRatio":
|
2024-12-25 19:31:12 +08:00
|
|
|
|
err = setting.CheckGroupRatio(option.Value)
|
2024-09-20 18:09:40 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
|
"success": false,
|
|
|
|
|
|
"message": err.Error(),
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-05-05 20:00:06 +08:00
|
|
|
|
case "ModelRequestRateLimitGroup":
|
|
|
|
|
|
err = setting.CheckModelRequestRateLimitGroup(option.Value)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
|
"success": false,
|
|
|
|
|
|
"message": err.Error(),
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-06-14 00:40:29 +08:00
|
|
|
|
case "console_setting.api_info":
|
|
|
|
|
|
err = console_setting.ValidateApiInfo(option.Value)
|
✨ feat: major refactor and enhancement of Detail dashboard component & add api url display
- **Code Organization & Architecture:**
- Restructured component with clear sections (Hooks, Constants, Helper Functions, etc.)
- Added comprehensive code organization comments for better maintainability
- Extracted reusable helper functions and constants for better separation of concerns
- **Performance Optimizations:**
- Implemented extensive use of useCallback and useMemo hooks for expensive operations
- Optimized data processing pipeline with dedicated processing functions
- Memoized chart configurations, performance metrics, and grouped stats data
- Cached helper functions like getTrendSpec, handleCopyUrl, and modal handlers
- **UI/UX Enhancements:**
- Added Empty state component with construction illustrations for better UX
- Implemented responsive grid layout with conditional API info section visibility
- Enhanced button styling with consistent rounded design and hover effects
- Added mini trend charts to statistics cards for visual data representation
- Improved form field consistency with reusable createFormField helper
- **Feature Improvements:**
- Added self-use mode detection to conditionally hide/show API information section
- Enhanced chart configurations with centralized CHART_CONFIG constant
- Improved time handling with dedicated helper functions (getTimeInterval, getInitialTimestamp)
- Added comprehensive performance metrics calculation (RPM/TPM trends)
- Implemented advanced data aggregation and processing workflows
- **Code Quality & Maintainability:**
- Extracted complex data processing logic into dedicated functions
- Added proper prop destructuring and state organization
- Implemented consistent naming conventions and helper utilities
- Enhanced error handling and loading states management
- Added comprehensive JSDoc-style comments for better code documentation
- **Technical Debt Reduction:**
- Replaced repetitive form field definitions with reusable components
- Consolidated chart update logic into centralized updateChartSpec function
- Improved data flow with better state management patterns
- Reduced code duplication through strategic use of helper functions
This refactor significantly improves component performance, maintainability, and user experience while maintaining backward compatibility and existing functionality.
2025-06-09 17:44:23 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
|
"success": false,
|
|
|
|
|
|
"message": err.Error(),
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-06-14 00:40:29 +08:00
|
|
|
|
case "console_setting.announcements":
|
|
|
|
|
|
err = console_setting.ValidateConsoleSettings(option.Value, "Announcements")
|
2025-06-10 20:10:07 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
|
"success": false,
|
|
|
|
|
|
"message": err.Error(),
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-06-14 00:40:29 +08:00
|
|
|
|
case "console_setting.faq":
|
|
|
|
|
|
err = console_setting.ValidateConsoleSettings(option.Value, "FAQ")
|
2025-06-10 20:10:07 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
|
"success": false,
|
|
|
|
|
|
"message": err.Error(),
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2023-04-22 20:39:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
err = model.UpdateOption(option.Key, option.Value)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
|
"success": false,
|
|
|
|
|
|
"message": err.Error(),
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
|
|
"success": true,
|
|
|
|
|
|
"message": "",
|
|
|
|
|
|
})
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|