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() {