refactor(router): check auto_scan_enabled before starting watch mode

- Add check for auto_scan_enabled setting in router before starting watch mode
- Update StartScanner handler to verify auto-scan is enabled
- Switch scanner to use watchModeCtx/watchModeCancel instead of ctx/cancel
- Update StartWatchModeForLibrary to use new MediaScanner signature
This commit is contained in:
2026-02-28 12:57:27 -05:00
parent ce72781ec0
commit 5a2e1fda65
2 changed files with 22 additions and 25 deletions
+15
View File
@@ -13,6 +13,7 @@ import (
"context"
"log"
"net/http"
"strconv"
"strings"
"time"
@@ -238,6 +239,20 @@ func RegisterRoutes(cfg *Config) *handlers.Handler {
// Start watch mode for all libraries (after 2 second delay for DB)
go func() {
time.Sleep(2 * time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
setting, err := cfg.Queries.GetSystemSetting(ctx, "auto_scan_enabled")
enabled := true // default
if err == nil && setting != "" {
enabled, _ = strconv.ParseBool(setting)
}
if !enabled {
log.Println("Auto-scan disabled in settings, skipping watch mode startup")
return
}
log.Println("Starting watch mode for all libraries...")
if err := scannerHandler.StartWatchModeForAllLibraries(context.Background()); err != nil {
log.Printf("Failed to start watch mode: %v", err)