diff --git a/internal/services/worker.go b/internal/services/worker.go index 050adf0..da7c0d4 100644 --- a/internal/services/worker.go +++ b/internal/services/worker.go @@ -305,6 +305,19 @@ func (w *Worker) processJob(job *Job) { NewItems: newItems, Errors: errors, } + + if job.Type == JobTypeScan && w.connManager != nil && job.UserID != "" { + w.connManager.BroadcastToUser(job.UserID, wsync.BroadcastMessage{ + Type: wsync.MessageTypeScanComplete, + Data: map[string]interface{}{ + "job_id": job.ID, + "files_scanned": filesScanned, + "new_items": newItems, + "errors": errors, + }, + }) + } + w.mu.Unlock() } @@ -888,9 +901,9 @@ func (w *Worker) processDirectoryScanJob(job *Job) (interface{}, error) { // Create temporary scanner instance for this job scanner := NewMediaScanner(db) scanner.job = job - // Find which library owns this directory + // Find which library owns this directory (prefix match for subdirectories) ctx := context.Background() - libRow, err := db.GetLibraryByFolder(ctx, directory) + libRow, err := db.GetLibraryByFolderPathPrefix(ctx, directory) if err != nil { return nil, fmt.Errorf("directory not associated with any library: %s", directory) }