diff --git a/src/server/torr/apihelper.go b/src/server/torr/apihelper.go index bc04af2..edcfaef 100644 --- a/src/server/torr/apihelper.go +++ b/src/server/torr/apihelper.go @@ -56,10 +56,19 @@ func SaveTorrentToDB(torr *Torrent) { func GetTorrent(hashHex string) *Torrent { hash := metainfo.NewHashFromHex(hashHex) tor := bts.GetTorrent(hash) - if tor == nil { - tor = GetTorrentDB(hash) + if tor != nil { + 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 } diff --git a/src/server/torr/torrent.go b/src/server/torr/torrent.go index f71d6c1..cda9196 100644 --- a/src/server/torr/torrent.go +++ b/src/server/torr/torrent.go @@ -19,7 +19,6 @@ import ( ) type Torrent struct { - ///// info for db Title string Poster string *torrent.TorrentSpec @@ -27,7 +26,6 @@ type Torrent struct { Stat state.TorrentStat Timestamp int64 Size int64 - ///// *torrent.Torrent muTorrent sync.Mutex @@ -363,7 +361,7 @@ func (t *Torrent) Status() *state.TorrentStatus { st.Name = t.Torrent.Name() st.Hash = t.Torrent.InfoHash().HexString() st.LoadedSize = t.Torrent.BytesCompleted() - st.TorrentSize = t.Torrent.Length() + st.PreloadedBytes = t.PreloadedBytes st.PreloadSize = t.PreloadSize st.DownloadSpeed = t.DownloadSpeed @@ -387,18 +385,20 @@ func (t *Torrent) Status() *state.TorrentStatus { st.ConnectedSeeders = tst.ConnectedSeeders 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 { - 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(), + files := t.Files() + 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(), + }) + } } } return st