Big commit

This commit is contained in:
Ben Sarmiento
2023-10-24 22:14:04 +02:00
parent 91472334b9
commit 2ce8273779
8 changed files with 105 additions and 71 deletions

View File

@@ -1,7 +1,6 @@
package dav
import (
"fmt"
"log"
"net/http"
"path"
@@ -40,15 +39,15 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent
torrents := t.FindAllTorrentsWithName(baseDirectory, torrentName)
if torrents == nil {
log.Println("Cannot find torrent", torrentName)
log.Println("Cannot find torrent", requestPath)
http.Error(w, "Cannot find file", http.StatusNotFound)
return
}
filenameV2, linkFragment := davextra.ExtractLinkFragment(filename)
torrent, file := getFile(torrents, filenameV2, linkFragment)
_, file := getFile(torrents, filenameV2, linkFragment)
if file == nil {
log.Println("Cannot find file", filename)
log.Println("Cannot find file", requestPath)
http.Error(w, "Cannot find file", http.StatusNotFound)
return
}
@@ -65,8 +64,8 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent
resp := realdebrid.RetryUntilOk(unrestrictFn)
if resp == nil {
log.Println("Cannot unrestrict link", link, filenameV2)
t.MarkFileAsDeleted(torrent, file)
http.Error(w, "Cannot find file", http.StatusNotFound)
// t.HideTheFile(torrent, file)
http.Redirect(w, r, "https://send.nukes.wtf/tDeTd0", http.StatusFound)
return
}
if resp.Filename != filenameV2 {
@@ -87,7 +86,7 @@ func getFile(torrents []torrent.Torrent, filename, fragment string) (*torrent.To
for t := range torrents {
for f, file := range torrents[t].SelectedFiles {
fname := filepath.Base(file.Path)
if filename == fname && strings.HasPrefix(file.Link, fmt.Sprintf("https://real-debrid.com/d/%s", fragment)) {
if filename == fname && strings.Contains(file.Link, fragment) {
return &torrents[t], &torrents[t].SelectedFiles[f]
}
}