This commit is contained in:
yourok
2018-08-29 12:33:14 +03:00
commit 0ca43a2c4d
54 changed files with 5669 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
package server
import (
"server/torr"
"server/web/helpers"
)
type TorrentStat struct {
Name string
Hash string
TorrentStatus int
TorrentStatusString string
LoadedSize int64
TorrentSize int64
PreloadedBytes int64
PreloadSize int64
DownloadSpeed float64
UploadSpeed float64
TotalPeers int
PendingPeers int
ActivePeers int
ConnectedSeeders int
FileStats []FileStat
}
type FileStat struct {
Id int
Path string
Length int64
}
func getTorPlayState(tor *torr.Torrent) TorrentStat {
tst := tor.Stats()
ts := TorrentStat{}
ts.Name = tst.Name
ts.Hash = tst.Hash
ts.TorrentStatus = int(tst.TorrentStatus)
ts.TorrentStatusString = tst.TorrentStatusString
ts.LoadedSize = tst.LoadedSize
ts.TorrentSize = tst.TorrentSize
ts.PreloadedBytes = tst.PreloadedBytes
ts.PreloadSize = tst.PreloadSize
ts.DownloadSpeed = tst.DownloadSpeed
ts.UploadSpeed = tst.UploadSpeed
ts.TotalPeers = tst.TotalPeers
ts.PendingPeers = tst.PendingPeers
ts.ActivePeers = tst.ActivePeers
ts.ConnectedSeeders = tst.ConnectedSeeders
files := helpers.GetPlayableFiles(tst)
ts.FileStats = make([]FileStat, len(files))
for i, f := range files {
ts.FileStats[i] = FileStat{
Id: f.Id,
Path: f.Path,
Length: f.Length,
}
}
return ts
}