Implement autoheal feature

This commit is contained in:
Ben Sarmiento
2023-10-23 20:01:55 +02:00
parent 6298830ea6
commit 21cbb16b88
6 changed files with 218 additions and 86 deletions

View File

@@ -64,23 +64,19 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent
}
resp := realdebrid.RetryUntilOk(unrestrictFn)
if resp == nil {
// TODO: Readd the file
// when unrestricting fails, it means the file is not available anymore, but still in their database
// if it's the only file, tough luck
// 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
}
if resp.Filename != filenameV2 {
// TODO: Redo the logic to handle 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
// Action: schedule a "cleanup" job for the parent torrent
// If the file extension changed, that means it's a different file
log.Println("Filename mismatch", resp.Filename, filenameV2)
actualExt := filepath.Ext(resp.Filename)
expectedExt := filepath.Ext(filenameV2)
if actualExt != expectedExt {
log.Println("File extension mismatch", resp.Filename, filenameV2)
} else {
log.Println("Filename mismatch", resp.Filename, filenameV2)
}
}
cache.Add(requestPath, resp.Download)
http.Redirect(w, r, resp.Download, http.StatusFound)

View File

@@ -52,8 +52,7 @@ func createSingleTorrentResponse(basePath string, torrents []torrent.Torrent) (*
for _, torrent := range torrents {
for _, file := range torrent.SelectedFiles {
if file.Link == "" {
// TODO: Fix this file
log.Println("File has no link, skipping", file.Path)
log.Println("File has no link, skipping (repairing links take time)", file.Path)
continue
}