use a new thread safe map

This commit is contained in:
Ben Sarmiento
2023-11-18 12:53:39 +01:00
parent b669f8d673
commit 0e9302f3b5
15 changed files with 577 additions and 535 deletions

View File

@@ -43,8 +43,14 @@ func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torren
accessKey := segments[len(segments)-2]
filename := segments[len(segments)-1]
torrent, _ := t.TorrentMap.Get(accessKey)
if torrent == nil {
torrents, ok := t.DirectoryMap.Get(baseDirectory)
if !ok {
log.Warnf("Cannot find directory %s", baseDirectory)
http.Error(w, "File not found", http.StatusNotFound)
return
}
torrent, ok := torrents.Get(accessKey)
if !ok {
log.Warnf("Cannot find torrent %s in the directory %s", accessKey, baseDirectory)
http.Error(w, "File not found", http.StatusNotFound)
return