fix play without auth

This commit is contained in:
YouROK
2021-03-25 11:07:35 +03:00
parent ba0b5aabd1
commit 74422ca9b6

View File

@@ -4,7 +4,6 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
"server/torr"
"server/torr/state"
@@ -144,16 +143,7 @@ func streamNoAuth(c *gin.Context) {
return
}
if title == "" {
title = c.Param("fname")
title, _ = url.PathUnescape(title)
title = strings.TrimLeft(title, "/")
} else {
title, _ = url.QueryUnescape(title)
}
link, _ = url.QueryUnescape(link)
poster, _ = url.QueryUnescape(poster)
spec, err := utils.ParseLink(link)
if err != nil {
@@ -162,12 +152,16 @@ func streamNoAuth(c *gin.Context) {
}
tor := torr.GetTorrent(spec.InfoHash.HexString())
if tor != nil {
title = tor.Title
poster = tor.Poster
data = tor.Data
if tor == nil {
c.AbortWithStatus(http.StatusForbidden)
return
}
if tor == nil || tor.Stat == state.TorrentInDB {
title = tor.Title
poster = tor.Poster
data = tor.Data
if tor.Stat == state.TorrentInDB {
tor, err = torr.AddTorrent(spec, title, poster, data)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
@@ -180,10 +174,6 @@ func streamNoAuth(c *gin.Context) {
return
}
if tor.Title == "" {
tor.Title = tor.Name()
}
// find file
index := -1
if len(tor.Files()) == 1 {