proper marking of file as deleted
This commit is contained in:
@@ -40,12 +40,18 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent
|
||||
}
|
||||
|
||||
filenameV2, linkFragment := davextra.ExtractLinkFragment(filename)
|
||||
link := getLink(torrents, filenameV2, linkFragment)
|
||||
if link == "" {
|
||||
torrent, file := getFile(torrents, filenameV2, linkFragment)
|
||||
if file == nil {
|
||||
log.Println("Cannot find file", filename)
|
||||
http.Error(w, "Cannot find file", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if file.Link == "" {
|
||||
log.Println("Link not found", filename)
|
||||
http.Error(w, "Cannot find file", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
link := file.Link
|
||||
|
||||
unrestrictFn := func() (*realdebrid.UnrestrictResponse, error) {
|
||||
return realdebrid.UnrestrictLink(c.GetToken(), link)
|
||||
@@ -58,6 +64,7 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent
|
||||
// if it's the only file, try to readd it
|
||||
// delete the old one, add a new one
|
||||
log.Println("Cannot unrestrict link", link, filenameV2)
|
||||
t.MarkFileAsDeleted(torrent, file)
|
||||
http.Error(w, "Cannot find file", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
@@ -72,15 +79,15 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent
|
||||
http.Redirect(w, r, resp.Download, http.StatusFound)
|
||||
}
|
||||
|
||||
// getLink finds a link by a fragment, it might be wrong
|
||||
func getLink(torrents []torrent.Torrent, filename, fragment string) string {
|
||||
for _, torrent := range torrents {
|
||||
for _, file := range torrent.SelectedFiles {
|
||||
// getFile finds a link by a fragment, it might be wrong
|
||||
func getFile(torrents []torrent.Torrent, filename, fragment string) (*torrent.Torrent, *torrent.File) {
|
||||
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)) {
|
||||
return file.Link
|
||||
return &torrents[t], &torrents[t].SelectedFiles[f]
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user