mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 12:20:52 +08:00
refactor(config): disable automatic migration during server startup
This commit is contained in:
@@ -493,14 +493,15 @@ func LoadConfig(configFile string) (*Config, error) {
|
|||||||
// If optional is true and the file is missing, it returns an empty Config.
|
// If optional is true and the file is missing, it returns an empty Config.
|
||||||
// If optional is true and the file is empty or invalid, it returns an empty Config.
|
// If optional is true and the file is empty or invalid, it returns an empty Config.
|
||||||
func LoadConfigOptional(configFile string, optional bool) (*Config, error) {
|
func LoadConfigOptional(configFile string, optional bool) (*Config, error) {
|
||||||
// Perform oauth-model-alias migration before loading config.
|
// NOTE: Startup oauth-model-alias migration is intentionally disabled.
|
||||||
// This migrates oauth-model-mappings to oauth-model-alias if needed.
|
// Reason: avoid mutating config.yaml during server startup.
|
||||||
if migrated, err := MigrateOAuthModelAlias(configFile); err != nil {
|
// Re-enable the block below if automatic startup migration is needed again.
|
||||||
// Log warning but don't fail - config loading should still work
|
// if migrated, err := MigrateOAuthModelAlias(configFile); err != nil {
|
||||||
fmt.Printf("Warning: oauth-model-alias migration failed: %v\n", err)
|
// // Log warning but don't fail - config loading should still work
|
||||||
} else if migrated {
|
// fmt.Printf("Warning: oauth-model-alias migration failed: %v\n", err)
|
||||||
fmt.Println("Migrated oauth-model-mappings to oauth-model-alias")
|
// } else if migrated {
|
||||||
}
|
// fmt.Println("Migrated oauth-model-mappings to oauth-model-alias")
|
||||||
|
// }
|
||||||
|
|
||||||
// Read the entire configuration file into memory.
|
// Read the entire configuration file into memory.
|
||||||
data, err := os.ReadFile(configFile)
|
data, err := os.ReadFile(configFile)
|
||||||
@@ -540,18 +541,21 @@ func LoadConfigOptional(configFile string, optional bool) (*Config, error) {
|
|||||||
return nil, fmt.Errorf("failed to parse config file: %w", err)
|
return nil, fmt.Errorf("failed to parse config file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var legacy legacyConfigData
|
// NOTE: Startup legacy key migration is intentionally disabled.
|
||||||
if errLegacy := yaml.Unmarshal(data, &legacy); errLegacy == nil {
|
// Reason: avoid mutating config.yaml during server startup.
|
||||||
if cfg.migrateLegacyGeminiKeys(legacy.LegacyGeminiKeys) {
|
// Re-enable the block below if automatic startup migration is needed again.
|
||||||
cfg.legacyMigrationPending = true
|
// var legacy legacyConfigData
|
||||||
}
|
// if errLegacy := yaml.Unmarshal(data, &legacy); errLegacy == nil {
|
||||||
if cfg.migrateLegacyOpenAICompatibilityKeys(legacy.OpenAICompat) {
|
// if cfg.migrateLegacyGeminiKeys(legacy.LegacyGeminiKeys) {
|
||||||
cfg.legacyMigrationPending = true
|
// cfg.legacyMigrationPending = true
|
||||||
}
|
// }
|
||||||
if cfg.migrateLegacyAmpConfig(&legacy) {
|
// if cfg.migrateLegacyOpenAICompatibilityKeys(legacy.OpenAICompat) {
|
||||||
cfg.legacyMigrationPending = true
|
// cfg.legacyMigrationPending = true
|
||||||
}
|
// }
|
||||||
}
|
// if cfg.migrateLegacyAmpConfig(&legacy) {
|
||||||
|
// cfg.legacyMigrationPending = true
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// Hash remote management key if plaintext is detected (nested)
|
// Hash remote management key if plaintext is detected (nested)
|
||||||
// We consider a value to be already hashed if it looks like a bcrypt hash ($2a$, $2b$, or $2y$ prefix).
|
// We consider a value to be already hashed if it looks like a bcrypt hash ($2a$, $2b$, or $2y$ prefix).
|
||||||
@@ -612,17 +616,20 @@ func LoadConfigOptional(configFile string, optional bool) (*Config, error) {
|
|||||||
// Validate raw payload rules and drop invalid entries.
|
// Validate raw payload rules and drop invalid entries.
|
||||||
cfg.SanitizePayloadRules()
|
cfg.SanitizePayloadRules()
|
||||||
|
|
||||||
if cfg.legacyMigrationPending {
|
// NOTE: Legacy migration persistence is intentionally disabled together with
|
||||||
fmt.Println("Detected legacy configuration keys, attempting to persist the normalized config...")
|
// startup legacy migration to keep startup read-only for config.yaml.
|
||||||
if !optional && configFile != "" {
|
// Re-enable the block below if automatic startup migration is needed again.
|
||||||
if err := SaveConfigPreserveComments(configFile, &cfg); err != nil {
|
// if cfg.legacyMigrationPending {
|
||||||
return nil, fmt.Errorf("failed to persist migrated legacy config: %w", err)
|
// fmt.Println("Detected legacy configuration keys, attempting to persist the normalized config...")
|
||||||
}
|
// if !optional && configFile != "" {
|
||||||
fmt.Println("Legacy configuration normalized and persisted.")
|
// if err := SaveConfigPreserveComments(configFile, &cfg); err != nil {
|
||||||
} else {
|
// return nil, fmt.Errorf("failed to persist migrated legacy config: %w", err)
|
||||||
fmt.Println("Legacy configuration normalized in memory; persistence skipped.")
|
// }
|
||||||
}
|
// fmt.Println("Legacy configuration normalized and persisted.")
|
||||||
}
|
// } else {
|
||||||
|
// fmt.Println("Legacy configuration normalized in memory; persistence skipped.")
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// Return the populated configuration struct.
|
// Return the populated configuration struct.
|
||||||
return &cfg, nil
|
return &cfg, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user