fix crash

This commit is contained in:
YouROK
2021-03-11 15:12:46 +03:00
parent c03ea41cb4
commit 001faf7a97

View File

@@ -7,6 +7,7 @@ import (
"strings" "strings"
"server/torr" "server/torr"
"server/torr/state"
"server/web/api/utils" "server/web/api/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -36,6 +37,7 @@ func stream(c *gin.Context) {
_, play := c.GetQuery("play") _, play := c.GetQuery("play")
title := c.Query("title") title := c.Query("title")
poster := c.Query("poster") poster := c.Query("poster")
data := ""
notAuth := c.GetBool("not_auth") notAuth := c.GetBool("not_auth")
if notAuth && play { if notAuth && play {
@@ -53,6 +55,7 @@ func stream(c *gin.Context) {
return return
} }
title, _ = url.QueryUnescape(title)
link, _ = url.QueryUnescape(link) link, _ = url.QueryUnescape(link)
poster, _ = url.QueryUnescape(poster) poster, _ = url.QueryUnescape(poster)
@@ -63,16 +66,19 @@ func stream(c *gin.Context) {
} }
tor := torr.GetTorrent(spec.InfoHash.HexString()) tor := torr.GetTorrent(spec.InfoHash.HexString())
if tor == nil { if tor != nil {
title = tor.Title
poster = tor.Poster
data = tor.Data
}
if tor == nil || tor.Stat == state.TorrentInDB {
if title == "" { if title == "" {
title = c.Param("fname") title = c.Param("fname")
title, _ = url.PathUnescape(title) title, _ = url.PathUnescape(title)
title = strings.TrimLeft(title, "/") title = strings.TrimLeft(title, "/")
} else {
title, _ = url.QueryUnescape(title)
} }
tor, err = torr.AddTorrent(spec, title, poster, "") tor, err = torr.AddTorrent(spec, title, poster, data)
if err != nil { if err != nil {
c.AbortWithError(http.StatusInternalServerError, err) c.AbortWithError(http.StatusInternalServerError, err)
return return