minor cleanup
Some checks failed
Release Docker Build / docker (push) Has been cancelled
GoReleaser / goreleaser (push) Has been cancelled

This commit is contained in:
Mukhtar Akere
2025-10-16 21:04:14 +01:00
parent 2a4f09c06d
commit f93d1a5913
2 changed files with 9 additions and 8 deletions

View File

@@ -184,7 +184,11 @@ func (c *Cache) MarkLinkAsInvalid(downloadLink types.DownloadLink, reason string
c.logger.Error().Str("token", utils.Mask(downloadLink.Token)).Msg("Account not found to delete download link") c.logger.Error().Str("token", utils.Mask(downloadLink.Token)).Msg("Account not found to delete download link")
return return
} }
c.client.DeleteDownloadLink(account, downloadLink)
if err := c.client.DeleteDownloadLink(account, downloadLink); err != nil {
c.logger.Error().Err(err).Str("token", utils.Mask(downloadLink.Token)).Msg("Failed to delete download link from account")
return
}
} }
} }

View File

@@ -104,9 +104,6 @@ func (c *Cache) Stream(ctx context.Context, start, end int64, linkFunc func() (t
} }
if streamErr.LinkError { if streamErr.LinkError {
c.logger.Trace().
Int("retries", retry).
Msg("Link error, getting fresh link")
lastErr = streamErr lastErr = streamErr
// Try new link // Try new link
downloadLink, err = linkFunc() downloadLink, err = linkFunc()
@@ -116,7 +113,7 @@ func (c *Cache) Stream(ctx context.Context, start, end int64, linkFunc func() (t
continue continue
} }
// Retryable HTTP error (429, 503, etc.) - retry network // Retryable HTTP error (429, 503, 404 etc.) - retry network
lastErr = streamErr lastErr = streamErr
c.logger.Trace(). c.logger.Trace().
Err(lastErr). Err(lastErr).
@@ -198,9 +195,6 @@ func (c *Cache) doRequest(ctx context.Context, url string, start, end int64) (*h
} }
func (c *Cache) handleHTTPError(resp *http.Response, downloadLink types.DownloadLink) StreamError { func (c *Cache) handleHTTPError(resp *http.Response, downloadLink types.DownloadLink) StreamError {
body, _ := io.ReadAll(resp.Body)
bodyStr := strings.ToLower(string(body))
switch resp.StatusCode { switch resp.StatusCode {
case http.StatusNotFound: case http.StatusNotFound:
c.MarkLinkAsInvalid(downloadLink, "link_not_found") c.MarkLinkAsInvalid(downloadLink, "link_not_found")
@@ -211,6 +205,8 @@ func (c *Cache) handleHTTPError(resp *http.Response, downloadLink types.Download
} }
case http.StatusServiceUnavailable: case http.StatusServiceUnavailable:
body, _ := io.ReadAll(resp.Body)
bodyStr := strings.ToLower(string(body))
if strings.Contains(bodyStr, "bandwidth") || strings.Contains(bodyStr, "traffic") { if strings.Contains(bodyStr, "bandwidth") || strings.Contains(bodyStr, "traffic") {
c.MarkLinkAsInvalid(downloadLink, "bandwidth_exceeded") c.MarkLinkAsInvalid(downloadLink, "bandwidth_exceeded")
return StreamError{ return StreamError{
@@ -230,6 +226,7 @@ func (c *Cache) handleHTTPError(resp *http.Response, downloadLink types.Download
default: default:
retryable := resp.StatusCode >= 500 retryable := resp.StatusCode >= 500
body, _ := io.ReadAll(resp.Body)
return StreamError{ return StreamError{
Err: fmt.Errorf("HTTP %d: %s", resp.StatusCode, string(body)), Err: fmt.Errorf("HTTP %d: %s", resp.StatusCode, string(body)),
Retryable: retryable, Retryable: retryable,