diff --git a/internal/universal/downloader.go b/internal/universal/downloader.go index 5a49be4..2cd5fe8 100644 --- a/internal/universal/downloader.go +++ b/internal/universal/downloader.go @@ -49,7 +49,7 @@ func (dl *Downloader) DownloadFile(directory, torrentName, fileName string, resp // log.Debugf("Opening file %s from torrent %s (%s)", fileName, torMgr.GetKey(torrent), file.Link) if file.IsBroken { if cfg.EnableRepair() { - http.Error(resp, "File is temporarily unavailable", http.StatusLocked) + http.Error(resp, "File is temporarily unavailable", http.StatusNotFound) } else { http.Error(resp, "File is not available", http.StatusNotFound) } @@ -65,7 +65,7 @@ func (dl *Downloader) DownloadFile(directory, torrentName, fileName string, resp } else { log.Warnf("Repair is disabled, skipping repair for unavailable file %s (link=%s)", fileName, file.Link) } - http.Error(resp, "File is not available", http.StatusInternalServerError) + http.Error(resp, "File is not available", http.StatusNotFound) return } else { if unrestrict.Filesize != file.Bytes { @@ -80,7 +80,7 @@ func (dl *Downloader) DownloadFile(directory, torrentName, fileName string, resp } } if cfg.ShouldServeFromRclone() { - redirect(resp, req, unrestrict.Download, cfg) + redirect(resp, req, unrestrict.Download) } else { dl.streamFileToResponse(torrent, file, unrestrict, resp, req, torMgr, cfg, log) } @@ -98,7 +98,7 @@ func (dl *Downloader) DownloadLink(fileName, link string, resp http.ResponseWrit return } else { if cfg.ShouldServeFromRclone() { - redirect(resp, req, unrestrict.Download, cfg) + redirect(resp, req, unrestrict.Download) } else { dl.streamFileToResponse(nil, nil, unrestrict, resp, req, torMgr, cfg, log) } @@ -143,7 +143,7 @@ func (dl *Downloader) streamFileToResponse(torrent *intTor.Torrent, file *intTor } else { log.Warnf("Cannot download file %s: %v", unrestrict.Download, err) } - http.Error(resp, "File is not available", http.StatusInternalServerError) + http.Error(resp, "File is not available", http.StatusNotFound) return } defer download.Body.Close() @@ -160,7 +160,7 @@ func (dl *Downloader) streamFileToResponse(torrent *intTor.Torrent, file *intTor } else { log.Warnf("Received a %s status code for file %s", download.Status, unrestrict.Download) } - http.Error(resp, "File is not available", http.StatusInternalServerError) + http.Error(resp, "File is not available", http.StatusNotFound) return } @@ -176,6 +176,6 @@ func (dl *Downloader) streamFileToResponse(torrent *intTor.Torrent, file *intTor io.CopyBuffer(resp, download.Body, buf) } -func redirect(resp http.ResponseWriter, req *http.Request, url string, cfg config.ConfigInterface) { +func redirect(resp http.ResponseWriter, req *http.Request, url string) { http.Redirect(resp, req, url, http.StatusFound) }