handleGetSettings returns current settings.
(w http.ResponseWriter, r *http.Request)
| 366 | |
| 367 | // handleGetSettings returns current settings. |
| 368 | func (s *Server) handleGetSettings(w http.ResponseWriter, r *http.Request) { |
| 369 | // Read a consistent snapshot so we never observe a field mid-update. |
| 370 | cfg := s.settingsConfig() |
| 371 | |
| 372 | // Don't expose full token, just indicate if set |
| 373 | tokenStatus := "" |
| 374 | if cfg.Token != "" { |
| 375 | tokenStatus = "********" + cfg.Token[max(0, len(cfg.Token)-4):] |
| 376 | } |
| 377 | |
| 378 | cacheDir := cfg.CacheDir |
| 379 | if cacheDir == "" { |
| 380 | cacheDir = hfdownloader.DefaultCacheDir() |
| 381 | } |
| 382 | |
| 383 | storageMode := "cache" |
| 384 | if cfg.LocalDir != "" { |
| 385 | storageMode = "local" |
| 386 | } |
| 387 | |
| 388 | resp := SettingsResponse{ |
| 389 | Token: tokenStatus, |
| 390 | CacheDir: cacheDir, |
| 391 | Concurrency: cfg.Concurrency, |
| 392 | MaxActive: cfg.MaxActive, |
| 393 | MultipartThreshold: cfg.MultipartThreshold, |
| 394 | Verify: cfg.Verify, |
| 395 | Retries: cfg.Retries, |
| 396 | Endpoint: cfg.Endpoint, |
| 397 | StorageMode: storageMode, |
| 398 | LocalDir: cfg.LocalDir, |
| 399 | ConfigFile: ConfigPath(), |
| 400 | TargetsFile: hfdownloader.DefaultTargetsPath(), |
| 401 | } |
| 402 | |
| 403 | // Add proxy settings (without password for security) |
| 404 | if cfg.Proxy != nil && cfg.Proxy.URL != "" { |
| 405 | resp.Proxy = &ProxySettingsResponse{ |
| 406 | URL: cfg.Proxy.URL, |
| 407 | Username: cfg.Proxy.Username, |
| 408 | NoProxy: cfg.Proxy.NoProxy, |
| 409 | NoEnvProxy: cfg.Proxy.NoEnvProxy, |
| 410 | InsecureSkipVerify: cfg.Proxy.InsecureSkipVerify, |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | writeJSON(w, http.StatusOK, resp) |
| 415 | } |
| 416 | |
| 417 | // handleUpdateSettings updates settings and persists them to config file. |
| 418 | // Note: Output directories cannot be changed via API for security. |