Fix unrestrict issue

This commit is contained in:
Ben Sarmiento
2023-11-28 00:41:15 +01:00
parent c8334ecb3b
commit 3d380e468f
9 changed files with 131 additions and 68 deletions

View File

@@ -8,7 +8,6 @@ import (
"strings"
"github.com/debridmediamanager.com/zurg/internal/torrent"
"github.com/hashicorp/golang-lru/v2/expirable"
"go.uber.org/zap"
)
@@ -16,7 +15,7 @@ const (
SPLIT_TOKEN = "$"
)
func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, cache *expirable.LRU[string, string], log *zap.SugaredLogger) {
func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, log *zap.SugaredLogger) {
requestPath := path.Clean(r.URL.Path)
requestPath = strings.Replace(requestPath, "/http", "", 1)
if requestPath == "/favicon.ico" {
@@ -31,18 +30,6 @@ func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torren
return
}
if data, exists := cache.Get("head:" + requestPath); exists {
splits := strings.Split(data, SPLIT_TOKEN)
contentType := splits[0]
contentLength := splits[1]
lastModified := splits[2]
w.Header().Set("Content-Type", contentType)
w.Header().Set("Content-Length", contentLength)
w.Header().Set("Last-Modified", lastModified)
w.WriteHeader(http.StatusOK)
return
}
baseDirectory := segments[len(segments)-3]
accessKey := segments[len(segments)-2]
filename := segments[len(segments)-1]
@@ -78,8 +65,6 @@ func HandleHeadRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torren
w.Header().Set("Content-Type", contentType)
w.Header().Set("Content-Length", contentLength)
w.Header().Set("Last-Modified", lastModified)
cacheVal := strings.Join([]string{contentType, contentLength, lastModified}, SPLIT_TOKEN)
cache.Add("head:"+requestPath, cacheVal)
w.WriteHeader(http.StatusOK)
}