| |
| package mapper |
|
|
| import ( |
| "github.com/router-for-me/CLIProxyAPI/v6/internal/application/dto" |
| "github.com/router-for-me/CLIProxyAPI/v6/internal/config" |
| ) |
|
|
| |
| func ToConfigResponse(cfg *config.Config) *dto.ConfigResponse { |
| if cfg == nil { |
| return &dto.ConfigResponse{ |
| Routing: dto.RoutingConfig{Strategy: "round-robin"}, |
| RemoteManagement: dto.RemoteManagementConfig{}, |
| QuotaExceeded: dto.QuotaExceededConfig{}, |
| AmpCode: config.AmpCode{}, |
| } |
| } |
|
|
| return &dto.ConfigResponse{ |
| Debug: cfg.Debug, |
| UsageStatisticsEnabled: cfg.UsageStatisticsEnabled, |
| LoggingToFile: cfg.LoggingToFile, |
| LogsMaxTotalSizeMB: cfg.LogsMaxTotalSizeMB, |
| RequestLog: cfg.RequestLog, |
| WebsocketAuth: cfg.WebsocketAuth, |
| RequestRetry: cfg.RequestRetry, |
| MaxRetryInterval: cfg.MaxRetryInterval, |
| ForceModelPrefix: cfg.ForceModelPrefix, |
| ProxyURL: cfg.ProxyURL, |
| Routing: dto.RoutingConfig{ |
| Strategy: cfg.Routing.Strategy, |
| }, |
| RemoteManagement: dto.RemoteManagementConfig{ |
| AllowRemote: cfg.RemoteManagement.AllowRemote, |
| SecretKey: cfg.RemoteManagement.SecretKey, |
| }, |
| QuotaExceeded: dto.QuotaExceededConfig{ |
| SwitchProject: cfg.QuotaExceeded.SwitchProject, |
| SwitchPreviewModel: cfg.QuotaExceeded.SwitchPreviewModel, |
| }, |
| APIKeys: cfg.APIKeys, |
| GeminiKey: cfg.GeminiKey, |
| ClaudeKey: cfg.ClaudeKey, |
| CodexKey: cfg.CodexKey, |
| OpenAICompatibility: cfg.OpenAICompatibility, |
| VertexCompatAPIKey: cfg.VertexCompatAPIKey, |
| KiroKey: cfg.KiroKey, |
| OAuthExcludedModels: cfg.OAuthExcludedModels, |
| OAuthModelAlias: cfg.OAuthModelAlias, |
| AmpCode: cfg.AmpCode, |
| } |
| } |
|
|
| |
| func ToConfig(req *dto.UpdateConfigRequest) *config.Config { |
| if req == nil { |
| return &config.Config{} |
| } |
| return &req.Config |
| } |
|
|
| |
| func ToConfigFromResponse(resp *dto.ConfigResponse) *config.Config { |
| if resp == nil { |
| return &config.Config{} |
| } |
|
|
| cfg := &config.Config{ |
| Debug: resp.Debug, |
| UsageStatisticsEnabled: resp.UsageStatisticsEnabled, |
| LoggingToFile: resp.LoggingToFile, |
| LogsMaxTotalSizeMB: resp.LogsMaxTotalSizeMB, |
| WebsocketAuth: resp.WebsocketAuth, |
| RequestRetry: resp.RequestRetry, |
| MaxRetryInterval: resp.MaxRetryInterval, |
| Routing: config.RoutingConfig{ |
| Strategy: resp.Routing.Strategy, |
| }, |
| RemoteManagement: config.RemoteManagement{ |
| AllowRemote: resp.RemoteManagement.AllowRemote, |
| SecretKey: resp.RemoteManagement.SecretKey, |
| }, |
| QuotaExceeded: config.QuotaExceeded{ |
| SwitchProject: resp.QuotaExceeded.SwitchProject, |
| SwitchPreviewModel: resp.QuotaExceeded.SwitchPreviewModel, |
| }, |
| GeminiKey: resp.GeminiKey, |
| ClaudeKey: resp.ClaudeKey, |
| CodexKey: resp.CodexKey, |
| OpenAICompatibility: resp.OpenAICompatibility, |
| VertexCompatAPIKey: resp.VertexCompatAPIKey, |
| KiroKey: resp.KiroKey, |
| OAuthExcludedModels: resp.OAuthExcludedModels, |
| OAuthModelAlias: resp.OAuthModelAlias, |
| AmpCode: resp.AmpCode, |
| } |
|
|
| |
| cfg.SDKConfig.RequestLog = resp.RequestLog |
| cfg.SDKConfig.ForceModelPrefix = resp.ForceModelPrefix |
| cfg.SDKConfig.ProxyURL = resp.ProxyURL |
| cfg.SDKConfig.APIKeys = resp.APIKeys |
|
|
| return cfg |
| } |
|
|