This commit is contained in:
YouROK
2020-11-25 15:42:31 +03:00
parent e36f01bf5e
commit cb74792d4d
2 changed files with 24 additions and 15 deletions

View File

@@ -56,10 +56,19 @@ func SaveTorrentToDB(torr *Torrent) {
func GetTorrent(hashHex string) *Torrent { func GetTorrent(hashHex string) *Torrent {
hash := metainfo.NewHashFromHex(hashHex) hash := metainfo.NewHashFromHex(hashHex)
tor := bts.GetTorrent(hash) tor := bts.GetTorrent(hash)
if tor == nil { if tor != nil {
tor = GetTorrentDB(hash) return tor
} }
tor = GetTorrentDB(hash)
tr, err := NewTorrent(tor.TorrentSpec, bts)
if err != nil {
log.TLogln("error get torrent db:", err)
}
if tr != nil {
go tr.GotInfo()
}
return tor return tor
} }

View File

@@ -19,7 +19,6 @@ import (
) )
type Torrent struct { type Torrent struct {
///// info for db
Title string Title string
Poster string Poster string
*torrent.TorrentSpec *torrent.TorrentSpec
@@ -27,7 +26,6 @@ type Torrent struct {
Stat state.TorrentStat Stat state.TorrentStat
Timestamp int64 Timestamp int64
Size int64 Size int64
/////
*torrent.Torrent *torrent.Torrent
muTorrent sync.Mutex muTorrent sync.Mutex
@@ -363,7 +361,7 @@ func (t *Torrent) Status() *state.TorrentStatus {
st.Name = t.Torrent.Name() st.Name = t.Torrent.Name()
st.Hash = t.Torrent.InfoHash().HexString() st.Hash = t.Torrent.InfoHash().HexString()
st.LoadedSize = t.Torrent.BytesCompleted() st.LoadedSize = t.Torrent.BytesCompleted()
st.TorrentSize = t.Torrent.Length()
st.PreloadedBytes = t.PreloadedBytes st.PreloadedBytes = t.PreloadedBytes
st.PreloadSize = t.PreloadSize st.PreloadSize = t.PreloadSize
st.DownloadSpeed = t.DownloadSpeed st.DownloadSpeed = t.DownloadSpeed
@@ -387,18 +385,20 @@ func (t *Torrent) Status() *state.TorrentStatus {
st.ConnectedSeeders = tst.ConnectedSeeders st.ConnectedSeeders = tst.ConnectedSeeders
st.HalfOpenPeers = tst.HalfOpenPeers st.HalfOpenPeers = tst.HalfOpenPeers
files := t.Files() if t.Torrent.Info() != nil {
st.TorrentSize = t.Torrent.Length()
sort.Slice(files, func(i, j int) bool { files := t.Files()
return files[i].Path() < files[j].Path() sort.Slice(files, func(i, j int) bool {
}) return files[i].Path() < files[j].Path()
for i, f := range files {
st.FileStats = append(st.FileStats, state.TorrentFileStat{
Id: i + 1,
Path: f.Path(),
Length: f.Length(),
}) })
for i, f := range files {
st.FileStats = append(st.FileStats, state.TorrentFileStat{
Id: i + 1,
Path: f.Path(),
Length: f.Length(),
})
}
} }
} }
return st return st