2025-07-11 02:30:57 +08:00
|
|
|
package converter
|
|
|
|
|
|
|
|
|
|
import (
|
2025-07-29 17:04:49 +08:00
|
|
|
"strconv"
|
2025-07-11 02:30:57 +08:00
|
|
|
"time"
|
|
|
|
|
|
2025-07-18 09:42:07 +08:00
|
|
|
"github.com/ctwj/urldb/db/dto"
|
|
|
|
|
"github.com/ctwj/urldb/db/entity"
|
2025-07-30 00:01:42 +08:00
|
|
|
"github.com/ctwj/urldb/utils"
|
2025-07-11 02:30:57 +08:00
|
|
|
)
|
|
|
|
|
|
2025-07-29 17:04:49 +08:00
|
|
|
// SystemConfigToResponse 将系统配置实体列表转换为响应DTO
|
|
|
|
|
func SystemConfigToResponse(configs []entity.SystemConfig) *dto.SystemConfigResponse {
|
|
|
|
|
if len(configs) == 0 {
|
|
|
|
|
return getDefaultConfigResponse()
|
2025-07-11 02:30:57 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-29 17:04:49 +08:00
|
|
|
response := getDefaultConfigResponse()
|
2025-07-11 02:30:57 +08:00
|
|
|
|
2025-07-29 17:04:49 +08:00
|
|
|
// 将键值对转换为结构体
|
|
|
|
|
for _, config := range configs {
|
|
|
|
|
switch config.Key {
|
|
|
|
|
case entity.ConfigKeySiteTitle:
|
|
|
|
|
response.SiteTitle = config.Value
|
|
|
|
|
case entity.ConfigKeySiteDescription:
|
|
|
|
|
response.SiteDescription = config.Value
|
|
|
|
|
case entity.ConfigKeyKeywords:
|
|
|
|
|
response.Keywords = config.Value
|
|
|
|
|
case entity.ConfigKeyAuthor:
|
|
|
|
|
response.Author = config.Value
|
|
|
|
|
case entity.ConfigKeyCopyright:
|
|
|
|
|
response.Copyright = config.Value
|
2025-08-18 02:30:15 +08:00
|
|
|
case entity.ConfigKeySiteLogo:
|
|
|
|
|
response.SiteLogo = config.Value
|
2025-07-29 17:04:49 +08:00
|
|
|
case entity.ConfigKeyAutoProcessReadyResources:
|
|
|
|
|
if val, err := strconv.ParseBool(config.Value); err == nil {
|
|
|
|
|
response.AutoProcessReadyResources = val
|
|
|
|
|
}
|
|
|
|
|
case entity.ConfigKeyAutoProcessInterval:
|
|
|
|
|
if val, err := strconv.Atoi(config.Value); err == nil {
|
|
|
|
|
response.AutoProcessInterval = val
|
|
|
|
|
}
|
|
|
|
|
case entity.ConfigKeyAutoTransferEnabled:
|
|
|
|
|
if val, err := strconv.ParseBool(config.Value); err == nil {
|
|
|
|
|
response.AutoTransferEnabled = val
|
|
|
|
|
}
|
|
|
|
|
case entity.ConfigKeyAutoTransferLimitDays:
|
|
|
|
|
if val, err := strconv.Atoi(config.Value); err == nil {
|
|
|
|
|
response.AutoTransferLimitDays = val
|
|
|
|
|
}
|
|
|
|
|
case entity.ConfigKeyAutoTransferMinSpace:
|
|
|
|
|
if val, err := strconv.Atoi(config.Value); err == nil {
|
|
|
|
|
response.AutoTransferMinSpace = val
|
|
|
|
|
}
|
|
|
|
|
case entity.ConfigKeyAutoFetchHotDramaEnabled:
|
|
|
|
|
if val, err := strconv.ParseBool(config.Value); err == nil {
|
|
|
|
|
response.AutoFetchHotDramaEnabled = val
|
|
|
|
|
}
|
|
|
|
|
case entity.ConfigKeyApiToken:
|
|
|
|
|
response.ApiToken = config.Value
|
2025-08-02 23:45:26 +08:00
|
|
|
case entity.ConfigKeyForbiddenWords:
|
|
|
|
|
response.ForbiddenWords = config.Value
|
2025-08-13 00:28:18 +08:00
|
|
|
case entity.ConfigKeyAdKeywords:
|
|
|
|
|
response.AdKeywords = config.Value
|
|
|
|
|
case entity.ConfigKeyAutoInsertAd:
|
|
|
|
|
response.AutoInsertAd = config.Value
|
2025-07-29 17:04:49 +08:00
|
|
|
case entity.ConfigKeyPageSize:
|
|
|
|
|
if val, err := strconv.Atoi(config.Value); err == nil {
|
|
|
|
|
response.PageSize = val
|
|
|
|
|
}
|
|
|
|
|
case entity.ConfigKeyMaintenanceMode:
|
|
|
|
|
if val, err := strconv.ParseBool(config.Value); err == nil {
|
|
|
|
|
response.MaintenanceMode = val
|
|
|
|
|
}
|
2025-08-08 17:26:48 +08:00
|
|
|
case entity.ConfigKeyEnableRegister:
|
|
|
|
|
if val, err := strconv.ParseBool(config.Value); err == nil {
|
|
|
|
|
response.EnableRegister = val
|
|
|
|
|
}
|
2025-08-10 13:52:41 +08:00
|
|
|
case entity.ConfigKeyThirdPartyStatsCode:
|
|
|
|
|
response.ThirdPartyStatsCode = config.Value
|
2025-08-20 15:03:14 +08:00
|
|
|
case entity.ConfigKeyMeilisearchEnabled:
|
|
|
|
|
if val, err := strconv.ParseBool(config.Value); err == nil {
|
|
|
|
|
response.MeilisearchEnabled = val
|
|
|
|
|
}
|
|
|
|
|
case entity.ConfigKeyMeilisearchHost:
|
|
|
|
|
response.MeilisearchHost = config.Value
|
|
|
|
|
case entity.ConfigKeyMeilisearchPort:
|
|
|
|
|
response.MeilisearchPort = config.Value
|
|
|
|
|
case entity.ConfigKeyMeilisearchMasterKey:
|
|
|
|
|
response.MeilisearchMasterKey = config.Value
|
|
|
|
|
case entity.ConfigKeyMeilisearchIndexName:
|
|
|
|
|
response.MeilisearchIndexName = config.Value
|
2025-07-29 17:04:49 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-07-16 18:05:29 +08:00
|
|
|
|
2025-07-29 17:04:49 +08:00
|
|
|
// 设置时间戳(使用第一个配置的时间)
|
|
|
|
|
if len(configs) > 0 {
|
|
|
|
|
response.CreatedAt = configs[0].CreatedAt.Format(time.RFC3339)
|
|
|
|
|
response.UpdatedAt = configs[0].UpdatedAt.Format(time.RFC3339)
|
2025-07-11 02:30:57 +08:00
|
|
|
}
|
2025-07-29 17:04:49 +08:00
|
|
|
|
|
|
|
|
return response
|
2025-07-11 02:30:57 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-29 17:04:49 +08:00
|
|
|
// RequestToSystemConfig 将请求DTO转换为系统配置实体列表
|
|
|
|
|
func RequestToSystemConfig(req *dto.SystemConfigRequest) []entity.SystemConfig {
|
2025-07-11 02:30:57 +08:00
|
|
|
if req == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-02 23:45:26 +08:00
|
|
|
var configs []entity.SystemConfig
|
2025-08-18 13:38:52 +08:00
|
|
|
var updatedKeys []string
|
2025-08-02 23:45:26 +08:00
|
|
|
|
2025-08-18 13:38:52 +08:00
|
|
|
// 字符串字段 - 只处理被设置的字段
|
|
|
|
|
if req.SiteTitle != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeySiteTitle, Value: *req.SiteTitle, Type: entity.ConfigTypeString})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeySiteTitle)
|
|
|
|
|
}
|
|
|
|
|
if req.SiteDescription != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeySiteDescription, Value: *req.SiteDescription, Type: entity.ConfigTypeString})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeySiteDescription)
|
|
|
|
|
}
|
|
|
|
|
if req.Keywords != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyKeywords, Value: *req.Keywords, Type: entity.ConfigTypeString})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyKeywords)
|
|
|
|
|
}
|
|
|
|
|
if req.Author != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyAuthor, Value: *req.Author, Type: entity.ConfigTypeString})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyAuthor)
|
|
|
|
|
}
|
|
|
|
|
if req.Copyright != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyCopyright, Value: *req.Copyright, Type: entity.ConfigTypeString})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyCopyright)
|
|
|
|
|
}
|
|
|
|
|
if req.SiteLogo != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeySiteLogo, Value: *req.SiteLogo, Type: entity.ConfigTypeString})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeySiteLogo)
|
|
|
|
|
}
|
|
|
|
|
if req.ApiToken != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyApiToken, Value: *req.ApiToken, Type: entity.ConfigTypeString})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyApiToken)
|
|
|
|
|
}
|
|
|
|
|
if req.ForbiddenWords != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyForbiddenWords, Value: *req.ForbiddenWords, Type: entity.ConfigTypeString})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyForbiddenWords)
|
|
|
|
|
}
|
|
|
|
|
if req.AdKeywords != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyAdKeywords, Value: *req.AdKeywords, Type: entity.ConfigTypeString})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyAdKeywords)
|
|
|
|
|
}
|
|
|
|
|
if req.AutoInsertAd != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyAutoInsertAd, Value: *req.AutoInsertAd, Type: entity.ConfigTypeString})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyAutoInsertAd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 布尔值字段 - 只处理被设置的字段
|
|
|
|
|
if req.AutoProcessReadyResources != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyAutoProcessReadyResources, Value: strconv.FormatBool(*req.AutoProcessReadyResources), Type: entity.ConfigTypeBool})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyAutoProcessReadyResources)
|
|
|
|
|
}
|
|
|
|
|
if req.AutoTransferEnabled != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyAutoTransferEnabled, Value: strconv.FormatBool(*req.AutoTransferEnabled), Type: entity.ConfigTypeBool})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyAutoTransferEnabled)
|
|
|
|
|
}
|
|
|
|
|
if req.AutoFetchHotDramaEnabled != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyAutoFetchHotDramaEnabled, Value: strconv.FormatBool(*req.AutoFetchHotDramaEnabled), Type: entity.ConfigTypeBool})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyAutoFetchHotDramaEnabled)
|
|
|
|
|
}
|
|
|
|
|
if req.MaintenanceMode != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyMaintenanceMode, Value: strconv.FormatBool(*req.MaintenanceMode), Type: entity.ConfigTypeBool})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyMaintenanceMode)
|
|
|
|
|
}
|
|
|
|
|
if req.EnableRegister != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyEnableRegister, Value: strconv.FormatBool(*req.EnableRegister), Type: entity.ConfigTypeBool})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyEnableRegister)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 整数字段 - 只处理被设置的字段
|
|
|
|
|
if req.AutoProcessInterval != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyAutoProcessInterval, Value: strconv.Itoa(*req.AutoProcessInterval), Type: entity.ConfigTypeInt})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyAutoProcessInterval)
|
|
|
|
|
}
|
|
|
|
|
if req.AutoTransferLimitDays != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyAutoTransferLimitDays, Value: strconv.Itoa(*req.AutoTransferLimitDays), Type: entity.ConfigTypeInt})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyAutoTransferLimitDays)
|
|
|
|
|
}
|
|
|
|
|
if req.AutoTransferMinSpace != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyAutoTransferMinSpace, Value: strconv.Itoa(*req.AutoTransferMinSpace), Type: entity.ConfigTypeInt})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyAutoTransferMinSpace)
|
|
|
|
|
}
|
|
|
|
|
if req.PageSize != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyPageSize, Value: strconv.Itoa(*req.PageSize), Type: entity.ConfigTypeInt})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyPageSize)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 三方统计配置 - 只处理被设置的字段
|
|
|
|
|
if req.ThirdPartyStatsCode != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyThirdPartyStatsCode, Value: *req.ThirdPartyStatsCode, Type: entity.ConfigTypeString})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyThirdPartyStatsCode)
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-20 15:03:14 +08:00
|
|
|
// Meilisearch配置 - 只处理被设置的字段
|
|
|
|
|
if req.MeilisearchEnabled != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyMeilisearchEnabled, Value: strconv.FormatBool(*req.MeilisearchEnabled), Type: entity.ConfigTypeBool})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyMeilisearchEnabled)
|
|
|
|
|
}
|
|
|
|
|
if req.MeilisearchHost != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyMeilisearchHost, Value: *req.MeilisearchHost, Type: entity.ConfigTypeString})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyMeilisearchHost)
|
|
|
|
|
}
|
|
|
|
|
if req.MeilisearchPort != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyMeilisearchPort, Value: *req.MeilisearchPort, Type: entity.ConfigTypeString})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyMeilisearchPort)
|
|
|
|
|
}
|
|
|
|
|
if req.MeilisearchMasterKey != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyMeilisearchMasterKey, Value: *req.MeilisearchMasterKey, Type: entity.ConfigTypeString})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyMeilisearchMasterKey)
|
|
|
|
|
}
|
|
|
|
|
if req.MeilisearchIndexName != nil {
|
|
|
|
|
configs = append(configs, entity.SystemConfig{Key: entity.ConfigKeyMeilisearchIndexName, Value: *req.MeilisearchIndexName, Type: entity.ConfigTypeString})
|
|
|
|
|
updatedKeys = append(updatedKeys, entity.ConfigKeyMeilisearchIndexName)
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-18 13:38:52 +08:00
|
|
|
// 记录更新的配置项
|
|
|
|
|
if len(updatedKeys) > 0 {
|
|
|
|
|
utils.Info("配置更新 - 被修改的配置项: %v", updatedKeys)
|
|
|
|
|
}
|
2025-08-10 13:52:41 +08:00
|
|
|
|
2025-07-29 17:04:49 +08:00
|
|
|
return configs
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SystemConfigToPublicResponse 返回不含 api_token 的系统配置响应
|
|
|
|
|
func SystemConfigToPublicResponse(configs []entity.SystemConfig) map[string]interface{} {
|
|
|
|
|
response := map[string]interface{}{
|
|
|
|
|
entity.ConfigResponseFieldID: 0,
|
2025-07-30 00:01:42 +08:00
|
|
|
entity.ConfigResponseFieldCreatedAt: utils.GetCurrentTimeString(),
|
|
|
|
|
entity.ConfigResponseFieldUpdatedAt: utils.GetCurrentTimeString(),
|
2025-07-29 17:04:49 +08:00
|
|
|
entity.ConfigResponseFieldSiteTitle: entity.ConfigDefaultSiteTitle,
|
|
|
|
|
entity.ConfigResponseFieldSiteDescription: entity.ConfigDefaultSiteDescription,
|
|
|
|
|
entity.ConfigResponseFieldKeywords: entity.ConfigDefaultKeywords,
|
|
|
|
|
entity.ConfigResponseFieldAuthor: entity.ConfigDefaultAuthor,
|
|
|
|
|
entity.ConfigResponseFieldCopyright: entity.ConfigDefaultCopyright,
|
2025-08-18 02:30:15 +08:00
|
|
|
"site_logo": "",
|
2025-07-29 17:04:49 +08:00
|
|
|
entity.ConfigResponseFieldAutoProcessReadyResources: false,
|
|
|
|
|
entity.ConfigResponseFieldAutoProcessInterval: 30,
|
|
|
|
|
entity.ConfigResponseFieldAutoTransferEnabled: false,
|
|
|
|
|
entity.ConfigResponseFieldAutoTransferLimitDays: 0,
|
|
|
|
|
entity.ConfigResponseFieldAutoTransferMinSpace: 100,
|
|
|
|
|
entity.ConfigResponseFieldAutoFetchHotDramaEnabled: false,
|
2025-08-02 23:45:26 +08:00
|
|
|
entity.ConfigResponseFieldForbiddenWords: "",
|
2025-08-13 00:28:18 +08:00
|
|
|
entity.ConfigResponseFieldAdKeywords: "",
|
|
|
|
|
entity.ConfigResponseFieldAutoInsertAd: "",
|
2025-07-29 17:04:49 +08:00
|
|
|
entity.ConfigResponseFieldPageSize: 100,
|
|
|
|
|
entity.ConfigResponseFieldMaintenanceMode: false,
|
2025-08-08 17:26:48 +08:00
|
|
|
entity.ConfigResponseFieldEnableRegister: true, // 默认开启注册功能
|
2025-08-20 15:03:14 +08:00
|
|
|
entity.ConfigResponseFieldThirdPartyStatsCode: "",
|
|
|
|
|
entity.ConfigResponseFieldMeilisearchEnabled: false,
|
|
|
|
|
entity.ConfigResponseFieldMeilisearchHost: "localhost",
|
|
|
|
|
entity.ConfigResponseFieldMeilisearchPort: "7700",
|
|
|
|
|
entity.ConfigResponseFieldMeilisearchMasterKey: "",
|
|
|
|
|
entity.ConfigResponseFieldMeilisearchIndexName: "resources",
|
2025-07-29 17:04:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将键值对转换为map
|
|
|
|
|
for _, config := range configs {
|
|
|
|
|
switch config.Key {
|
|
|
|
|
case entity.ConfigKeySiteTitle:
|
|
|
|
|
response[entity.ConfigResponseFieldSiteTitle] = config.Value
|
|
|
|
|
case entity.ConfigKeySiteDescription:
|
|
|
|
|
response[entity.ConfigResponseFieldSiteDescription] = config.Value
|
|
|
|
|
case entity.ConfigKeyKeywords:
|
|
|
|
|
response[entity.ConfigResponseFieldKeywords] = config.Value
|
|
|
|
|
case entity.ConfigKeyAuthor:
|
|
|
|
|
response[entity.ConfigResponseFieldAuthor] = config.Value
|
|
|
|
|
case entity.ConfigKeyCopyright:
|
|
|
|
|
response[entity.ConfigResponseFieldCopyright] = config.Value
|
2025-08-18 02:30:15 +08:00
|
|
|
case entity.ConfigKeySiteLogo:
|
|
|
|
|
response["site_logo"] = config.Value
|
2025-07-29 17:04:49 +08:00
|
|
|
case entity.ConfigKeyAutoProcessReadyResources:
|
|
|
|
|
if val, err := strconv.ParseBool(config.Value); err == nil {
|
|
|
|
|
response[entity.ConfigResponseFieldAutoProcessReadyResources] = val
|
|
|
|
|
}
|
|
|
|
|
case entity.ConfigKeyAutoProcessInterval:
|
|
|
|
|
if val, err := strconv.Atoi(config.Value); err == nil {
|
|
|
|
|
response[entity.ConfigResponseFieldAutoProcessInterval] = val
|
|
|
|
|
}
|
|
|
|
|
case entity.ConfigKeyAutoTransferEnabled:
|
|
|
|
|
if val, err := strconv.ParseBool(config.Value); err == nil {
|
|
|
|
|
response[entity.ConfigResponseFieldAutoTransferEnabled] = val
|
|
|
|
|
}
|
|
|
|
|
case entity.ConfigKeyAutoTransferLimitDays:
|
|
|
|
|
if val, err := strconv.Atoi(config.Value); err == nil {
|
|
|
|
|
response[entity.ConfigResponseFieldAutoTransferLimitDays] = val
|
|
|
|
|
}
|
|
|
|
|
case entity.ConfigKeyAutoTransferMinSpace:
|
|
|
|
|
if val, err := strconv.Atoi(config.Value); err == nil {
|
|
|
|
|
response[entity.ConfigResponseFieldAutoTransferMinSpace] = val
|
|
|
|
|
}
|
|
|
|
|
case entity.ConfigKeyAutoFetchHotDramaEnabled:
|
|
|
|
|
if val, err := strconv.ParseBool(config.Value); err == nil {
|
|
|
|
|
response[entity.ConfigResponseFieldAutoFetchHotDramaEnabled] = val
|
|
|
|
|
}
|
2025-08-02 23:45:26 +08:00
|
|
|
case entity.ConfigKeyForbiddenWords:
|
|
|
|
|
response[entity.ConfigResponseFieldForbiddenWords] = config.Value
|
2025-08-13 00:28:18 +08:00
|
|
|
case entity.ConfigKeyAdKeywords:
|
|
|
|
|
response[entity.ConfigResponseFieldAdKeywords] = config.Value
|
|
|
|
|
case entity.ConfigKeyAutoInsertAd:
|
|
|
|
|
response[entity.ConfigResponseFieldAutoInsertAd] = config.Value
|
2025-07-29 17:04:49 +08:00
|
|
|
case entity.ConfigKeyPageSize:
|
|
|
|
|
if val, err := strconv.Atoi(config.Value); err == nil {
|
|
|
|
|
response[entity.ConfigResponseFieldPageSize] = val
|
|
|
|
|
}
|
|
|
|
|
case entity.ConfigKeyMaintenanceMode:
|
|
|
|
|
if val, err := strconv.ParseBool(config.Value); err == nil {
|
|
|
|
|
response[entity.ConfigResponseFieldMaintenanceMode] = val
|
|
|
|
|
}
|
2025-08-08 17:26:48 +08:00
|
|
|
case entity.ConfigKeyEnableRegister:
|
|
|
|
|
if val, err := strconv.ParseBool(config.Value); err == nil {
|
|
|
|
|
response[entity.ConfigResponseFieldEnableRegister] = val
|
|
|
|
|
}
|
2025-08-10 13:52:41 +08:00
|
|
|
case entity.ConfigKeyThirdPartyStatsCode:
|
|
|
|
|
response[entity.ConfigResponseFieldThirdPartyStatsCode] = config.Value
|
2025-08-20 15:03:14 +08:00
|
|
|
case entity.ConfigKeyMeilisearchEnabled:
|
|
|
|
|
if val, err := strconv.ParseBool(config.Value); err == nil {
|
|
|
|
|
response[entity.ConfigResponseFieldMeilisearchEnabled] = val
|
|
|
|
|
}
|
|
|
|
|
case entity.ConfigKeyMeilisearchHost:
|
|
|
|
|
response[entity.ConfigResponseFieldMeilisearchHost] = config.Value
|
|
|
|
|
case entity.ConfigKeyMeilisearchPort:
|
|
|
|
|
response[entity.ConfigResponseFieldMeilisearchPort] = config.Value
|
|
|
|
|
case entity.ConfigKeyMeilisearchMasterKey:
|
|
|
|
|
response[entity.ConfigResponseFieldMeilisearchMasterKey] = config.Value
|
|
|
|
|
case entity.ConfigKeyMeilisearchIndexName:
|
|
|
|
|
response[entity.ConfigResponseFieldMeilisearchIndexName] = config.Value
|
2025-07-29 17:04:49 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-07-11 02:30:57 +08:00
|
|
|
|
2025-07-29 17:04:49 +08:00
|
|
|
// 设置时间戳(使用第一个配置的时间)
|
|
|
|
|
if len(configs) > 0 {
|
2025-08-11 01:34:07 +08:00
|
|
|
response[entity.ConfigResponseFieldCreatedAt] = configs[0].CreatedAt.Format(utils.TimeFormatDateTime)
|
|
|
|
|
response[entity.ConfigResponseFieldUpdatedAt] = configs[0].UpdatedAt.Format(utils.TimeFormatDateTime)
|
2025-07-29 17:04:49 +08:00
|
|
|
}
|
2025-07-11 02:30:57 +08:00
|
|
|
|
2025-07-29 17:04:49 +08:00
|
|
|
return response
|
|
|
|
|
}
|
2025-07-16 18:05:29 +08:00
|
|
|
|
2025-07-29 17:04:49 +08:00
|
|
|
// getDefaultConfigResponse 获取默认配置响应
|
|
|
|
|
func getDefaultConfigResponse() *dto.SystemConfigResponse {
|
|
|
|
|
return &dto.SystemConfigResponse{
|
|
|
|
|
SiteTitle: entity.ConfigDefaultSiteTitle,
|
|
|
|
|
SiteDescription: entity.ConfigDefaultSiteDescription,
|
|
|
|
|
Keywords: entity.ConfigDefaultKeywords,
|
|
|
|
|
Author: entity.ConfigDefaultAuthor,
|
|
|
|
|
Copyright: entity.ConfigDefaultCopyright,
|
2025-08-18 02:30:15 +08:00
|
|
|
SiteLogo: "",
|
2025-07-29 17:04:49 +08:00
|
|
|
AutoProcessReadyResources: false,
|
|
|
|
|
AutoProcessInterval: 30,
|
|
|
|
|
AutoTransferEnabled: false,
|
|
|
|
|
AutoTransferLimitDays: 0,
|
|
|
|
|
AutoTransferMinSpace: 100,
|
|
|
|
|
AutoFetchHotDramaEnabled: false,
|
|
|
|
|
ApiToken: entity.ConfigDefaultApiToken,
|
2025-08-02 23:45:26 +08:00
|
|
|
ForbiddenWords: entity.ConfigDefaultForbiddenWords,
|
2025-08-13 00:28:18 +08:00
|
|
|
AdKeywords: entity.ConfigDefaultAdKeywords,
|
|
|
|
|
AutoInsertAd: entity.ConfigDefaultAutoInsertAd,
|
2025-07-29 17:04:49 +08:00
|
|
|
PageSize: 100,
|
|
|
|
|
MaintenanceMode: false,
|
2025-08-08 17:26:48 +08:00
|
|
|
EnableRegister: true, // 默认开启注册功能
|
2025-08-10 13:52:41 +08:00
|
|
|
ThirdPartyStatsCode: entity.ConfigDefaultThirdPartyStatsCode,
|
2025-08-20 15:03:14 +08:00
|
|
|
MeilisearchEnabled: false,
|
|
|
|
|
MeilisearchHost: entity.ConfigDefaultMeilisearchHost,
|
|
|
|
|
MeilisearchPort: entity.ConfigDefaultMeilisearchPort,
|
|
|
|
|
MeilisearchMasterKey: entity.ConfigDefaultMeilisearchMasterKey,
|
|
|
|
|
MeilisearchIndexName: entity.ConfigDefaultMeilisearchIndexName,
|
2025-07-11 02:30:57 +08:00
|
|
|
}
|
|
|
|
|
}
|