Hotfixes:

- Fix % error in url encode
- FIx alldebrid downloading bug
- Fix dupicate checks for newly added torrents
This commit is contained in:
Mukhtar Akere
2025-04-20 00:44:58 +01:00
parent dc8ee3d150
commit a27c5dd491
11 changed files with 137 additions and 92 deletions
+16 -14
View File
@@ -81,14 +81,14 @@ func (f *File) stream() (*http.Response, error) {
downloadLink = f.getDownloadLink() // Uses the first API key
if downloadLink == "" {
_log.Error().Msgf("Failed to get download link for %s. Empty download link", f.name)
return nil, fmt.Errorf("failed to get download link")
_log.Trace().Msgf("Failed to get download link for %s. Empty download link", f.name)
return nil, io.EOF
}
req, err := http.NewRequest("GET", downloadLink, nil)
if err != nil {
_log.Error().Msgf("Failed to create HTTP request: %s", err)
return nil, fmt.Errorf("failed to create HTTP request: %w", err)
_log.Trace().Msgf("Failed to create HTTP request: %s", err)
return nil, io.EOF
}
if f.offset > 0 {
@@ -97,7 +97,7 @@ func (f *File) stream() (*http.Response, error) {
resp, err := client.Do(req)
if err != nil {
return resp, fmt.Errorf("HTTP request error: %w", err)
return resp, io.EOF
}
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent {
@@ -113,15 +113,17 @@ func (f *File) stream() (*http.Response, error) {
b, _ := io.ReadAll(resp.Body)
err := resp.Body.Close()
if err != nil {
return nil, err
_log.Trace().Msgf("Failed to close response body: %s", err)
return nil, io.EOF
}
if strings.Contains(string(b), "You can not download this file because you have exceeded your traffic on this hoster") {
_log.Error().Msgf("Failed to get download link for %s. Download link expired", f.name)
_log.Trace().Msgf("Failed to get download link for %s. Download link expired", f.name)
f.cache.MarkDownloadLinkAsInvalid(f.link, downloadLink, "bandwidth_exceeded")
// Retry with a different API key if it's available
return f.stream()
} else {
return resp, fmt.Errorf("link not found")
_log.Trace().Msgf("Failed to get download link for %s. %s", f.name, string(b))
return resp, io.EOF
}
} else if resp.StatusCode == http.StatusNotFound {
@@ -132,12 +134,12 @@ func (f *File) stream() (*http.Response, error) {
// Generate a new download link
downloadLink = f.getDownloadLink()
if downloadLink == "" {
_log.Error().Msgf("Failed to get download link for %s", f.name)
return nil, fmt.Errorf("failed to get download link")
_log.Trace().Msgf("Failed to get download link for %s", f.name)
return nil, io.EOF
}
req, err = http.NewRequest("GET", downloadLink, nil)
if err != nil {
return nil, fmt.Errorf("failed to create HTTP request: %w", err)
return nil, io.EOF
}
if f.offset > 0 {
req.Header.Set("Range", fmt.Sprintf("bytes=%d-", f.offset))
@@ -151,13 +153,13 @@ func (f *File) stream() (*http.Response, error) {
closeResp()
// Read the body to consume the response
f.cache.MarkDownloadLinkAsInvalid(f.link, downloadLink, "link_not_found")
return resp, fmt.Errorf("link not found")
return resp, io.EOF
}
return resp, nil
} else {
closeResp()
return resp, fmt.Errorf("unexpected HTTP status: %d", resp.StatusCode)
return resp, io.EOF
}
}
@@ -194,7 +196,7 @@ func (f *File) Read(p []byte) (n int, err error) {
return 0, err
}
if resp == nil {
return 0, fmt.Errorf("failed to get response")
return 0, io.EOF
}
f.reader = resp.Body
+12 -11
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"github.com/rs/zerolog"
"github.com/sirrobot01/decypharr/internal/request"
"github.com/sirrobot01/decypharr/internal/utils"
"github.com/sirrobot01/decypharr/pkg/debrid/debrid"
"github.com/sirrobot01/decypharr/pkg/debrid/types"
"github.com/sirrobot01/decypharr/pkg/version"
@@ -103,7 +104,7 @@ func (h *Handler) getParentFiles() []os.FileInfo {
}
func (h *Handler) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (webdav.File, error) {
name = path.Clean("/" + name)
name = utils.UnescapePath(path.Clean("/" + name))
rootDir := h.getRootPath()
metadataOnly := ctx.Value("metadataOnly") != nil
@@ -261,16 +262,16 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// __all__ or torrents folder
// Manually build the xml
ttl = 30 * time.Second
if served := h.serveFromCacheIfValid(w, r, cacheKey, ttl); served {
return
}
// Refresh the parent XML
h.cache.RefreshListings(false)
// Check again if the cache is valid
// If not, we will use the default WebDAV handler
if served := h.serveFromCacheIfValid(w, r, cacheKey, ttl); served {
return
}
//if served := h.serveFromCacheIfValid(w, r, cacheKey, ttl); served {
// return
//}
//// Refresh the parent XML
//h.cache.RefreshListings(false)
//// Check again if the cache is valid
//// If not, we will use the default WebDAV handler
//if served := h.serveFromCacheIfValid(w, r, cacheKey, ttl); served {
// return
//}
}
if served := h.serveFromCacheIfValid(w, r, cacheKey, ttl); served {