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