mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
add set torrent, for set title,poster,data
This commit is contained in:
@@ -83,6 +83,25 @@ func GetTorrent(hashHex string) *Torrent {
|
|||||||
return tor
|
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) {
|
func RemTorrent(hashHex string) {
|
||||||
hash := metainfo.NewHashFromHex(hashHex)
|
hash := metainfo.NewHashFromHex(hashHex)
|
||||||
bts.RemoveTorrent(hash)
|
bts.RemoveTorrent(hash)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
//Action: add, get, rem, list, drop
|
//Action: add, get, set, rem, list, drop
|
||||||
type torrReqJS struct {
|
type torrReqJS struct {
|
||||||
requestI
|
requestI
|
||||||
Link string `json:"link,omitempty"`
|
Link string `json:"link,omitempty"`
|
||||||
@@ -41,6 +41,10 @@ func torrents(c *gin.Context) {
|
|||||||
{
|
{
|
||||||
getTorrent(req, c)
|
getTorrent(req, c)
|
||||||
}
|
}
|
||||||
|
case "set":
|
||||||
|
{
|
||||||
|
setTorrent(req, c)
|
||||||
|
}
|
||||||
case "rem":
|
case "rem":
|
||||||
{
|
{
|
||||||
remTorrent(req, c)
|
remTorrent(req, c)
|
||||||
@@ -53,6 +57,7 @@ func torrents(c *gin.Context) {
|
|||||||
{
|
{
|
||||||
dropTorrent(req, c)
|
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) {
|
func remTorrent(req torrReqJS, c *gin.Context) {
|
||||||
if req.Hash == "" {
|
if req.Hash == "" {
|
||||||
c.AbortWithError(http.StatusBadRequest, errors.New("hash is empty"))
|
c.AbortWithError(http.StatusBadRequest, errors.New("hash is empty"))
|
||||||
|
|||||||
Reference in New Issue
Block a user