Commit 8591e980de
Unregistered key
Layout: unified · split
internal/config.go +16 −8
| @@ -5,6 +5,7 @@ import ( | |||
| 5 | "context" | 5 | "context" |
| 6 | "encoding/json" | 6 | "encoding/json" |
| 7 | "fmt" | 7 | "fmt" |
| 8 | "sort" | ||
| 8 | 9 | ||
| 9 | // "io" | 10 | // "io" |
| 10 | "net/http" | 11 | "net/http" |
| @@ -77,8 +78,10 @@ type CurdConfig struct { | |||
| 77 | MyAnimeListImportDismissed bool `config:"MyAnimeListImportDismissed"` | 78 | MyAnimeListImportDismissed bool `config:"MyAnimeListImportDismissed"` |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | const DefaultMpvPlaybackStartTimeout = 20 | 81 | const ( |
| 81 | const maxMpvPlaybackStartTimeout = 600 | 82 | DefaultMpvPlaybackStartTimeout = 20 |
| 83 | maxMpvPlaybackStartTimeout = 600 | ||
| 84 | ) | ||
| 82 | 85 | ||
| 83 | func MpvPlaybackStartTimeoutDuration(config *CurdConfig) time.Duration { | 86 | func MpvPlaybackStartTimeoutDuration(config *CurdConfig) time.Duration { |
| 84 | seconds := DefaultMpvPlaybackStartTimeout | 87 | seconds := DefaultMpvPlaybackStartTimeout |
| @@ -313,7 +316,7 @@ func createDefaultConfig(path string) error { | |||
| 313 | 316 | ||
| 314 | // Ensure the directory exists | 317 | // Ensure the directory exists |
| 315 | dir := filepath.Dir(path) | 318 | dir := filepath.Dir(path) |
| 316 | if err := os.MkdirAll(dir, 0755); err != nil { | 319 | if err := os.MkdirAll(dir, 0o755); err != nil { |
| 317 | return fmt.Errorf("error creating directory: %v", err) | 320 | return fmt.Errorf("error creating directory: %v", err) |
| 318 | } | 321 | } |
| 319 | 322 | ||
| @@ -534,7 +537,7 @@ func loadToken(tokenPath string) (*AnilistToken, error) { | |||
| 534 | // saveToken saves the token to the token file | 537 | // saveToken saves the token to the token file |
| 535 | func saveToken(tokenPath string, token *AnilistToken) error { | 538 | func saveToken(tokenPath string, token *AnilistToken) error { |
| 536 | // Ensure directory exists | 539 | // Ensure directory exists |
| 537 | if err := os.MkdirAll(filepath.Dir(tokenPath), 0755); err != nil { | 540 | if err := os.MkdirAll(filepath.Dir(tokenPath), 0o755); err != nil { |
| 538 | return fmt.Errorf("failed to create directory: %w", err) | 541 | return fmt.Errorf("failed to create directory: %w", err) |
| 539 | } | 542 | } |
| 540 | 543 | ||
| @@ -543,7 +546,7 @@ func saveToken(tokenPath string, token *AnilistToken) error { | |||
| 543 | return fmt.Errorf("failed to marshal token: %w", err) | 546 | return fmt.Errorf("failed to marshal token: %w", err) |
| 544 | } | 547 | } |
| 545 | 548 | ||
| 546 | return os.WriteFile(tokenPath, data, 0600) | 549 | return os.WriteFile(tokenPath, data, 0o600) |
| 547 | } | 550 | } |
| 548 | 551 | ||
| 549 | // isTokenValid checks if the token is still valid | 552 | // isTokenValid checks if the token is still valid |
| @@ -584,7 +587,6 @@ func ChangeToken(config *CurdConfig, user *User) { | |||
| 584 | // Try browser-based OAuth first | 587 | // Try browser-based OAuth first |
| 585 | fmt.Println("Starting browser-based authentication...") | 588 | fmt.Println("Starting browser-based authentication...") |
| 586 | user.Token, err = authenticateWithBrowser(tokenPath) | 589 | user.Token, err = authenticateWithBrowser(tokenPath) |
| 587 | |||
| 588 | if err != nil { | 590 | if err != nil { |
| 589 | Log("Browser authentication failed: " + err.Error()) | 591 | Log("Browser authentication failed: " + err.Error()) |
| 590 | fmt.Printf("Browser authentication failed: %v\n", err) | 592 | fmt.Printf("Browser authentication failed: %v\n", err) |
| @@ -659,9 +661,15 @@ func SaveConfigToFile(path string, configMap map[string]string) error { | |||
| 659 | } | 661 | } |
| 660 | defer file.Close() | 662 | defer file.Close() |
| 661 | 663 | ||
| 664 | keys := make([]string, 0, len(configMap)) | ||
| 665 | for key := range configMap { | ||
| 666 | keys = append(keys, key) | ||
| 667 | } | ||
| 668 | sort.Strings(keys) | ||
| 669 | |||
| 662 | writer := bufio.NewWriter(file) | 670 | writer := bufio.NewWriter(file) |
| 663 | for key, value := range configMap { | 671 | for _, key := range keys { |
| 664 | line := fmt.Sprintf("%s=%s\n", key, value) | 672 | line := fmt.Sprintf("%s=%s\n", key, configMap[key]) |
| 665 | if _, err := writer.WriteString(line); err != nil { | 673 | if _, err := writer.WriteString(line); err != nil { |
| 666 | return err | 674 | return err |
| 667 | } | 675 | } |
internal/tracking.go +4 −3
| @@ -86,7 +86,8 @@ func EnsureTrackingConfigured(config *CurdConfig) error { | |||
| 86 | 86 | ||
| 87 | normalizeTrackingConfig(config) | 87 | normalizeTrackingConfig(config) |
| 88 | if config.TrackingConfigured { | 88 | if config.TrackingConfigured { |
| 89 | return persistTrackingConfig(config) | 89 | // NOTE: persistTrackingConfig is only needed when tracker is changed not every startup |
| 90 | return nil | ||
| 90 | } | 91 | } |
| 91 | 92 | ||
| 92 | options := []SelectionOption{ | 93 | options := []SelectionOption{ |
| @@ -376,7 +377,7 @@ func writeTrackingBackup(config *CurdConfig, action string, aniList, myAnimeList | |||
| 376 | } | 377 | } |
| 377 | 378 | ||
| 378 | backupDir := filepath.Join(os.ExpandEnv(config.StoragePath), "tracking-backups") | 379 | backupDir := filepath.Join(os.ExpandEnv(config.StoragePath), "tracking-backups") |
| 379 | if err := os.MkdirAll(backupDir, 0755); err != nil { | 380 | if err := os.MkdirAll(backupDir, 0o755); err != nil { |
| 380 | return "", err | 381 | return "", err |
| 381 | } | 382 | } |
| 382 | 383 | ||
| @@ -398,7 +399,7 @@ func writeTrackingBackup(config *CurdConfig, action string, aniList, myAnimeList | |||
| 398 | if err != nil { | 399 | if err != nil { |
| 399 | return "", err | 400 | return "", err |
| 400 | } | 401 | } |
| 401 | if err := os.WriteFile(backupPath, data, 0644); err != nil { | 402 | if err := os.WriteFile(backupPath, data, 0o644); err != nil { |
| 402 | return "", err | 403 | return "", err |
| 403 | } | 404 | } |
| 404 | return backupPath, nil | 405 | return backupPath, nil |