Refactor with ordered maps
This commit is contained in:
@@ -41,17 +41,17 @@ func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torren
|
||||
}
|
||||
|
||||
baseDirectory := segments[len(segments)-3]
|
||||
torrentName := segments[len(segments)-2]
|
||||
accessKey := segments[len(segments)-2]
|
||||
filename := segments[len(segments)-1]
|
||||
|
||||
torrents := t.FindAllTorrentsWithName(baseDirectory, torrentName)
|
||||
if torrents == nil {
|
||||
log.Errorf("Cannot find torrent %s in the directory %s", requestPath, baseDirectory)
|
||||
http.Error(w, "Cannot find file", http.StatusNotFound)
|
||||
torrent, _ := t.TorrentMap.Get(accessKey)
|
||||
if torrent == nil {
|
||||
log.Errorf("Cannot find torrent %s in the directory %s", accessKey, baseDirectory)
|
||||
http.Error(w, "File not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
_, file := getFile(torrents, filename)
|
||||
file, _ := torrent.SelectedFiles.Get(filename)
|
||||
if file == nil {
|
||||
log.Errorf("Cannot find file from path %s", requestPath)
|
||||
http.Error(w, "Cannot find file", http.StatusNotFound)
|
||||
|
||||
Reference in New Issue
Block a user