Fix http mount
This commit is contained in:
@@ -7,11 +7,12 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/debridmediamanager/zurg/internal/torrent"
|
||||
"github.com/debridmediamanager/zurg/internal/version"
|
||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
||||
)
|
||||
|
||||
func HandleHeadRequest(directory, torrentName, fileName string, w http.ResponseWriter, req *http.Request, torMgr *torrent.TorrentManager, log *logutil.Logger) {
|
||||
|
||||
func CheckFile(directory, torrentName, fileName string, w http.ResponseWriter, req *http.Request, torMgr *torrent.TorrentManager, log *logutil.Logger) {
|
||||
torrents, ok := torMgr.DirectoryMap.Get(directory)
|
||||
if !ok {
|
||||
log.Warnf("Cannot find directory %s", directory)
|
||||
@@ -46,6 +47,31 @@ func HandleHeadRequest(directory, torrentName, fileName string, w http.ResponseW
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func CheckDownloadLink(download *realdebrid.Download, w http.ResponseWriter, req *http.Request, torMgr *torrent.TorrentManager, log *logutil.Logger) {
|
||||
if !strings.HasPrefix(download.Link, "http") {
|
||||
// This is a dead file, serve an alternate file
|
||||
log.Warnf("File %s is no longer available", download.Filename)
|
||||
http.Error(w, "Cannot find file", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
contentType := getContentMimeType(download.Filename)
|
||||
contentLength := fmt.Sprintf("%d", download.Filesize)
|
||||
lastModified := download.Generated
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
w.Header().Set("Content-Length", contentLength)
|
||||
w.Header().Set("Last-Modified", lastModified)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func CheckVersionFile(w http.ResponseWriter, req *http.Request, torMgr *torrent.TorrentManager, log *logutil.Logger) {
|
||||
_, size := version.GetFile()
|
||||
contentType := getContentMimeType(version.FILE)
|
||||
contentLength := fmt.Sprintf("%d", size)
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
w.Header().Set("Content-Length", contentLength)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func getContentMimeType(filePath string) string {
|
||||
switch filepath.Ext(filePath) {
|
||||
case ".mkv":
|
||||
Reference in New Issue
Block a user