Clean up
This commit is contained in:
@@ -38,7 +38,7 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent
|
||||
}
|
||||
|
||||
filenameV2, linkFragment := davextra.ExtractLinkFragment(filename)
|
||||
link := findLinkByFragment(torrents, filenameV2, linkFragment)
|
||||
link := getLink(torrents, filenameV2, linkFragment)
|
||||
if link == "" {
|
||||
log.Println("Link not found")
|
||||
http.Error(w, "Cannot find file", http.StatusNotFound)
|
||||
@@ -50,27 +50,25 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent
|
||||
}
|
||||
resp := realdebrid.RetryUntilOk(unrestrictFn)
|
||||
if resp == nil {
|
||||
// TODO: Delete the link from the database
|
||||
// TODO: Readd the file
|
||||
// when unrestricting fails, it means the file is not available anymore
|
||||
// if it's the only file, tough luck
|
||||
log.Println("Cannot unrestrict link")
|
||||
http.Error(w, "Cannot find file", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if resp.Filename != filenameV2 {
|
||||
// TODO: Redo the logic to handle mismatch
|
||||
// Filename mismatch
|
||||
// [SRS] Pokemon S22E01-35 1080p WEBRip AAC 2.0 x264 CC.rar
|
||||
// Pokemon.S22E24.The.Secret.Princess.DUBBED.1080p.WEBRip.AAC.2.0.x264-SRS.mkv
|
||||
// Filename mismatch
|
||||
// Adventure.Time.S06E10.Something.Big.1080p.HMAX.WEBRip.DD.2.0.H.265.-EDGE2020.mkv
|
||||
// Adventure.Time.S06E03.James.II.1080p.HMAX.WEBRip.DD.2.0.H.265.-EDGE2020.mkv
|
||||
// Action: schedule a "cleanup" job for the parent torrent
|
||||
log.Println("Filename mismatch", resp.Filename, filenameV2)
|
||||
}
|
||||
http.Redirect(w, r, resp.Download, http.StatusFound)
|
||||
}
|
||||
|
||||
// findLinkByFragment finds a link by a fragment, it might be wrong
|
||||
func findLinkByFragment(torrents []torrent.Torrent, filename, fragment string) string {
|
||||
// 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 {
|
||||
fname := filepath.Base(file.Path)
|
||||
|
||||
Reference in New Issue
Block a user