From 5eaa673149a30879908efdecedb0d1e6913badd2 Mon Sep 17 00:00:00 2001 From: YouROK <8yourok8@mail.ru> Date: Thu, 11 Mar 2021 15:17:58 +0300 Subject: [PATCH] update auth --- server/web/api/stream.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/server/web/api/stream.go b/server/web/api/stream.go index 58b993d..453806b 100644 --- a/server/web/api/stream.go +++ b/server/web/api/stream.go @@ -138,6 +138,7 @@ func streamNoAuth(c *gin.Context) { _, preload := c.GetQuery("preload") title := c.Query("title") poster := c.Query("poster") + data := "" if link == "" { c.AbortWithError(http.StatusBadRequest, errors.New("link should not be empty")) @@ -162,9 +163,23 @@ func streamNoAuth(c *gin.Context) { } tor := torr.GetTorrent(spec.InfoHash.HexString()) - if tor == nil { - c.AbortWithError(http.StatusNotFound, errors.New("Torrent not found")) - return + if tor != nil { + title = tor.Title + poster = tor.Poster + data = tor.Data + } + if tor == nil || tor.Stat == state.TorrentInDB { + if title == "" { + title = c.Param("fname") + title, _ = url.PathUnescape(title) + title = strings.TrimLeft(title, "/") + } + + tor, err = torr.AddTorrent(spec, title, poster, data) + if err != nil { + c.AbortWithError(http.StatusInternalServerError, err) + return + } } if !tor.GotInfo() {