From 469c1459380dd4c74c8588e397cdb580ee36f09b Mon Sep 17 00:00:00 2001 From: YouROK <8yourok8@mail.ru> Date: Fri, 13 Nov 2020 21:11:20 +0300 Subject: [PATCH] update --- src/server/torr/apihelper.go | 19 ++++++++-- src/server/torr/state/state.go | 65 +++++++++++++++------------------- 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/src/server/torr/apihelper.go b/src/server/torr/apihelper.go index 9b62bb5..4d6d52d 100644 --- a/src/server/torr/apihelper.go +++ b/src/server/torr/apihelper.go @@ -3,10 +3,11 @@ package torr import ( "sort" - "github.com/anacrolix/torrent" - "github.com/anacrolix/torrent/metainfo" "server/log" sets "server/settings" + + "github.com/anacrolix/torrent" + "github.com/anacrolix/torrent/metainfo" ) var ( @@ -24,11 +25,19 @@ func AddTorrent(spec *torrent.TorrentSpec, title, poster string) (*Torrent, erro return nil, err } + torDB := GetTorrentDB(spec.InfoHash) + if torr.Title == "" { torr.Title = title + if title == "" && torDB != nil { + torr.Title = torDB.Title + } } if torr.Poster == "" { torr.Poster = poster + if torr.Poster == "" && torDB != nil { + torr.Poster = torDB.Poster + } } if torr.Title == "" { @@ -75,7 +84,11 @@ func ListTorrent() []*Torrent { } sort.Slice(ret, func(i, j int) bool { - return ret[i].Timestamp > ret[j].Timestamp + if ret[i].Timestamp != ret[j].Timestamp { + return ret[i].Timestamp > ret[j].Timestamp + } else { + return ret[i].Title > ret[j].Title + } }) return ret diff --git a/src/server/torr/state/state.go b/src/server/torr/state/state.go index 31208be..f4551b6 100644 --- a/src/server/torr/state/state.go +++ b/src/server/torr/state/state.go @@ -31,42 +31,35 @@ const ( ) type TorrentStatus struct { - Title string `json:"title"` - Poster string `json:"poster"` - Timestamp int64 `json:"timestamp"` - - Name string `json:"name,omitempty"` - Hash string `json:"hash,omitempty"` - - Stat TorrentStat `json:"stat"` - StatString string `json:"stat_string"` - - LoadedSize int64 `json:"loaded_size,omitempty"` - TorrentSize int64 `json:"torrent_size,omitempty"` - - PreloadedBytes int64 `json:"preloaded_bytes,omitempty"` - PreloadSize int64 `json:"preload_size,omitempty"` - - DownloadSpeed float64 `json:"download_speed,omitempty"` - UploadSpeed float64 `json:"upload_speed,omitempty"` - - TotalPeers int `json:"total_peers,omitempty"` - PendingPeers int `json:"pending_peers,omitempty"` - ActivePeers int `json:"active_peers,omitempty"` - ConnectedSeeders int `json:"connected_seeders,omitempty"` - HalfOpenPeers int `json:"half_open_peers,omitempty"` - - BytesWritten int64 `json:"bytes_written,omitempty"` - BytesWrittenData int64 `json:"bytes_written_data,omitempty"` - BytesRead int64 `json:"bytes_read,omitempty"` - BytesReadData int64 `json:"bytes_read_data,omitempty"` - BytesReadUsefulData int64 `json:"bytes_read_useful_data,omitempty"` - ChunksWritten int64 `json:"chunks_written,omitempty"` - ChunksRead int64 `json:"chunks_read,omitempty"` - ChunksReadUseful int64 `json:"chunks_read_useful,omitempty"` - ChunksReadWasted int64 `json:"chunks_read_wasted,omitempty"` - PiecesDirtiedGood int64 `json:"pieces_dirtied_good,omitempty"` - PiecesDirtiedBad int64 `json:"pieces_dirtied_bad,omitempty"` + Title string `json:"title"` + Poster string `json:"poster"` + Timestamp int64 `json:"timestamp"` + Name string `json:"name,omitempty"` + Hash string `json:"hash,omitempty"` + Stat TorrentStat `json:"stat"` + StatString string `json:"stat_string"` + LoadedSize int64 `json:"loaded_size,omitempty"` + TorrentSize int64 `json:"torrent_size,omitempty"` + PreloadedBytes int64 `json:"preloaded_bytes,omitempty"` + PreloadSize int64 `json:"preload_size,omitempty"` + DownloadSpeed float64 `json:"download_speed,omitempty"` + UploadSpeed float64 `json:"upload_speed,omitempty"` + TotalPeers int `json:"total_peers,omitempty"` + PendingPeers int `json:"pending_peers,omitempty"` + ActivePeers int `json:"active_peers,omitempty"` + ConnectedSeeders int `json:"connected_seeders,omitempty"` + HalfOpenPeers int `json:"half_open_peers,omitempty"` + BytesWritten int64 `json:"bytes_written,omitempty"` + BytesWrittenData int64 `json:"bytes_written_data,omitempty"` + BytesRead int64 `json:"bytes_read,omitempty"` + BytesReadData int64 `json:"bytes_read_data,omitempty"` + BytesReadUsefulData int64 `json:"bytes_read_useful_data,omitempty"` + ChunksWritten int64 `json:"chunks_written,omitempty"` + ChunksRead int64 `json:"chunks_read,omitempty"` + ChunksReadUseful int64 `json:"chunks_read_useful,omitempty"` + ChunksReadWasted int64 `json:"chunks_read_wasted,omitempty"` + PiecesDirtiedGood int64 `json:"pieces_dirtied_good,omitempty"` + PiecesDirtiedBad int64 `json:"pieces_dirtied_bad,omitempty"` FileStats []TorrentFileStat `json:"file_stats,omitempty"` }