- Refractor code

- Add a better logging for 429 when streaming
- Fix minor issues
This commit is contained in:
Mukhtar Akere
2025-04-01 06:37:10 +01:00
parent 8bf164451c
commit 7d954052ae
28 changed files with 214 additions and 179 deletions
+7
View File
@@ -118,8 +118,15 @@ func (f *File) Read(p []byte) (n int, err error) {
if err != nil {
return 0, fmt.Errorf("HTTP request error: %w", err)
}
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent {
resp.Body.Close()
_log := f.cache.GetLogger()
_log.Debug().
Str("downloadLink", downloadLink).
Str("link", f.link).
Str("torrentId", f.torrentId).
Msgf("Unexpected HTTP status: %d", resp.StatusCode)
return 0, fmt.Errorf("unexpected HTTP status: %d", resp.StatusCode)
}
f.reader = resp.Body
+4 -8
View File
@@ -56,19 +56,15 @@ func (h *Handler) RemoveAll(ctx context.Context, name string) error {
return os.ErrPermission
}
torrentName, filename := getName(rootDir, name)
torrentName, _ := getName(rootDir, name)
cachedTorrent := h.cache.GetTorrentByName(torrentName)
if cachedTorrent == nil {
h.logger.Debug().Msgf("Torrent not found: %s", torrentName)
return os.ErrNotExist
return nil // It's possible that the torrent was removed
}
if filename == "" {
h.cache.OnRemove(cachedTorrent.Id)
return nil
}
return os.ErrPermission
h.cache.OnRemove(cachedTorrent.Id)
return nil
}
// Rename implements webdav.FileSystem