diff --git a/server/torr/apihelper.go b/server/torr/apihelper.go index d6c4d75..5eb5572 100644 --- a/server/torr/apihelper.go +++ b/server/torr/apihelper.go @@ -83,6 +83,25 @@ func GetTorrent(hashHex string) *Torrent { return tor } +func SetTorrent(hashHex, title, poster, data string) *Torrent { + hash := metainfo.NewHashFromHex(hashHex) + tor := bts.GetTorrent(hash) + if tor != nil { + tor.Title = title + tor.Poster = poster + tor.Data = data + } + + tor = GetTorrentDB(hash) + if tor != nil { + tor.Title = title + tor.Poster = poster + tor.Data = data + AddTorrentDB(tor) + } + return tor +} + func RemTorrent(hashHex string) { hash := metainfo.NewHashFromHex(hashHex) bts.RemoveTorrent(hash) diff --git a/server/web/api/torrents.go b/server/web/api/torrents.go index 977425d..5e928b8 100644 --- a/server/web/api/torrents.go +++ b/server/web/api/torrents.go @@ -13,7 +13,7 @@ import ( "github.com/pkg/errors" ) -//Action: add, get, rem, list, drop +//Action: add, get, set, rem, list, drop type torrReqJS struct { requestI Link string `json:"link,omitempty"` @@ -41,6 +41,10 @@ func torrents(c *gin.Context) { { getTorrent(req, c) } + case "set": + { + setTorrent(req, c) + } case "rem": { remTorrent(req, c) @@ -53,6 +57,7 @@ func torrents(c *gin.Context) { { dropTorrent(req, c) } + } } @@ -107,6 +112,15 @@ func getTorrent(req torrReqJS, c *gin.Context) { } } +func setTorrent(req torrReqJS, c *gin.Context) { + if req.Hash == "" { + c.AbortWithError(http.StatusBadRequest, errors.New("hash is empty")) + return + } + torr.SetTorrent(req.Hash, req.Title, req.Poster, req.Data) + c.Status(200) +} + func remTorrent(req torrReqJS, c *gin.Context) { if req.Hash == "" { c.AbortWithError(http.StatusBadRequest, errors.New("hash is empty"))