diff --git a/scanner/scanner.go b/scanner/scanner.go index b9b28338..3b1f2361 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -158,13 +158,11 @@ func (s *scanner) RescanAll(ctx context.Context, fullRescan bool) error { return nil } -func (s *scanner) getStatus(folder string) *scanStatus { +func (s *scanner) getStatus(folder string) (scanStatus, bool) { s.lock.RLock() defer s.lock.RUnlock() - if status, ok := s.status[folder]; ok { - return status - } - return nil + status, ok := s.status[folder] + return *status, ok } func (s *scanner) incStatusCounter(folder string, numFiles uint32) (totalFolders uint32, totalFiles uint32) { @@ -199,8 +197,8 @@ func (s *scanner) setStatusEnd(folder string, lastUpdate time.Time) { } func (s *scanner) Status(mediaFolder string) (*StatusInfo, error) { - status := s.getStatus(mediaFolder) - if status == nil { + status, ok := s.getStatus(mediaFolder) + if !ok { return nil, errors.New("mediaFolder not found") } return &StatusInfo{ diff --git a/server/events/sse.go b/server/events/sse.go index 59f5cb0c..82aa690d 100644 --- a/server/events/sse.go +++ b/server/events/sse.go @@ -111,7 +111,7 @@ func writeEvent(w io.Writer, event message, timeout time.Duration) error { _, err := fmt.Fprintf(w, "id: %d\nevent: %s\ndata: %s\n\n", event.id, event.event, event.data) // If the writer is an http.Flusher, flush the data immediately. - if flusher, ok := w.(http.Flusher); ok { + if flusher, ok := w.(http.Flusher); ok && flusher != nil { flusher.Flush() } @@ -135,7 +135,7 @@ func (b *broker) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Make sure that the writer supports flushing. _, ok := w.(http.Flusher) if !ok { - log.Error(w, "Streaming unsupported! Events cannot be sent to this client", "address", r.RemoteAddr, + log.Error(r, "Streaming unsupported! Events cannot be sent to this client", "address", r.RemoteAddr, "userAgent", r.UserAgent(), "user", user.UserName) http.Error(w, "Streaming unsupported!", http.StatusInternalServerError) return