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:
@@ -136,7 +136,10 @@ func (h *Handler) StartScanner(c echo.Context) error {
|
||||
h.scanner.SetAdminID(pgtype.UUID{Bytes: userUUID, Valid: true})
|
||||
|
||||
// Start watching for changes
|
||||
h.scanner.WatchChanges(h.ctx)
|
||||
if !h.scanner.GetAutoScanEnabled() {
|
||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "auto-scan disabled in settings"})
|
||||
}
|
||||
h.scanner.WatchChanges(h.watchModeCtx)
|
||||
|
||||
return c.JSON(http.StatusOK, map[string]string{"message": "scanner started"})
|
||||
}
|
||||
@@ -146,8 +149,8 @@ func (h *Handler) StopScanner(c echo.Context) error {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
|
||||
h.cancel()
|
||||
h.ctx, h.cancel = context.WithCancel(context.Background())
|
||||
h.watchModeCancel()
|
||||
h.watchModeCtx, h.watchModeCancel = context.WithCancel(context.Background())
|
||||
|
||||
return c.JSON(http.StatusOK, map[string]string{"message": "scanner stopped"})
|
||||
}
|
||||
@@ -197,7 +200,7 @@ func (h *Handler) StartWatchModeForLibrary(ctx context.Context, libraryID pgtype
|
||||
folderPaths[i] = folder.FolderPath
|
||||
}
|
||||
|
||||
scanner := services.NewMediaScanner(h.db, 3)
|
||||
scanner := services.NewMediaScanner(h.db)
|
||||
if err := scanner.SetFolders(folderPaths); err != nil {
|
||||
return fmt.Errorf("failed to set scanner folders: %v", err)
|
||||
}
|
||||
@@ -329,24 +332,3 @@ func (h *Handler) StartWatchModeForAllLibraries(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// StartScheduler starts the auto-scan scheduler
|
||||
func (h *Handler) StartScheduler() {
|
||||
h.scheduler.Start()
|
||||
}
|
||||
|
||||
// StopScheduler stops the auto-scan scheduler
|
||||
func (h *Handler) StopScheduler() {
|
||||
h.scheduler.Stop()
|
||||
h.worker.Shutdown()
|
||||
|
||||
// Stop the sync queue processor
|
||||
if h.queueCancel != nil {
|
||||
h.queueCancel()
|
||||
}
|
||||
|
||||
// Stop connection manager cleanup task
|
||||
if h.cleanupTaskCancel != nil {
|
||||
h.cleanupTaskCancel()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user