mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
update
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
package torr
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sort"
|
||||
|
||||
"github.com/anacrolix/torrent"
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
"server/log"
|
||||
sets "server/settings"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -24,13 +24,12 @@ func AddTorrent(spec *torrent.TorrentSpec, title, poster string) (*Torrent, erro
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !torr.GotInfo() {
|
||||
log.TLogln("error add torrent:", "timeout connection torrent")
|
||||
return nil, errors.New("timeout connection torrent")
|
||||
if torr.Title == "" {
|
||||
torr.Title = title
|
||||
}
|
||||
if torr.Poster == "" {
|
||||
torr.Poster = poster
|
||||
}
|
||||
|
||||
torr.Title = title
|
||||
torr.Poster = poster
|
||||
|
||||
if torr.Title == "" {
|
||||
torr.Title = torr.Name()
|
||||
@@ -86,3 +85,9 @@ func DropTorrent(hashHex string) {
|
||||
hash := metainfo.NewHashFromHex(hashHex)
|
||||
bts.RemoveTorrent(hash)
|
||||
}
|
||||
|
||||
func SetSettings(set *sets.BTSets) {
|
||||
bts.Disconnect()
|
||||
sets.SetBTSets(set)
|
||||
bts.Connect()
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func (t *Torrent) Stream(fileIndex int, req *http.Request, resp http.ResponseWriter) error {
|
||||
t.WaitInfo()
|
||||
files := t.Files()
|
||||
if fileIndex < 1 || fileIndex > len(files) {
|
||||
return errors.New("file index out of range")
|
||||
|
||||
@@ -27,5 +27,5 @@ func SetupRoute(route *gin.Engine) {
|
||||
}
|
||||
|
||||
func echo(c *gin.Context) {
|
||||
c.String(200, "{\"version\": \"%v\"}", version.Version)
|
||||
c.String(200, "%v", version.Version)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
sets "server/settings"
|
||||
"server/torr"
|
||||
)
|
||||
|
||||
//Action: get, set
|
||||
@@ -27,7 +28,7 @@ func settings(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if req.Action == "set" {
|
||||
sets.SetBTSets(req.Sets)
|
||||
torr.SetSettings(req.Sets)
|
||||
c.Status(200)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -65,6 +65,11 @@ func stream(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if !tor.GotInfo() {
|
||||
c.AbortWithError(http.StatusInternalServerError, errors.New("timeout connection torrent"))
|
||||
return
|
||||
}
|
||||
|
||||
// save to db
|
||||
if save {
|
||||
torr.SaveTorrentToDB(tor)
|
||||
|
||||
@@ -75,12 +75,18 @@ func addTorrent(req torrReqJS, c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if req.SaveToDB {
|
||||
torr.SaveTorrentToDB(tor)
|
||||
}
|
||||
go func() {
|
||||
if !tor.GotInfo() {
|
||||
log.TLogln("error add torrent:", "timeout connection torrent")
|
||||
return
|
||||
}
|
||||
|
||||
st := tor.Status()
|
||||
c.JSON(200, st)
|
||||
if req.SaveToDB {
|
||||
torr.SaveTorrentToDB(tor)
|
||||
}
|
||||
}()
|
||||
|
||||
c.JSON(200, tor.Status())
|
||||
}
|
||||
|
||||
func getTorrent(req torrReqJS, c *gin.Context) {
|
||||
@@ -109,6 +115,10 @@ func remTorrent(req torrReqJS, c *gin.Context) {
|
||||
|
||||
func listTorrent(req torrReqJS, c *gin.Context) {
|
||||
list := torr.ListTorrent()
|
||||
if list == nil {
|
||||
c.Status(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
var stats []*state.TorrentStatus
|
||||
for _, tr := range list {
|
||||
stats = append(stats, tr.Status())
|
||||
|
||||
Reference in New Issue
Block a user