From 5b70badb507256a85dd478684e2bb0e2d70b8e7d Mon Sep 17 00:00:00 2001 From: Simon Ding Date: Sun, 11 Aug 2024 20:41:26 +0800 Subject: [PATCH] feat: add seed ratio display --- server/activity.go | 4 +++- server/core/scheduler.go | 4 ++-- ui/lib/activity.dart | 13 ++++++++----- ui/lib/providers/activity.dart | 5 ++++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/server/activity.go b/server/activity.go index 2c3134e..99d8f12 100644 --- a/server/activity.go +++ b/server/activity.go @@ -15,7 +15,8 @@ import ( type Activity struct { *ent.History - Progress int `json:"progress"` + Progress int `json:"progress"` + SeedRatio float32 `json:"seed_ratio"` } func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) { @@ -35,6 +36,7 @@ func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) { for id, task := range s.core.GetTasks() { if h.ID == id && task.Exists() { a.Progress = task.Progress() + a.SeedRatio = float32(*task.SeedRatio()) } } activities = append(activities, a) diff --git a/server/core/scheduler.go b/server/core/scheduler.go index b8a21f9..d9047f0 100644 --- a/server/core/scheduler.go +++ b/server/core/scheduler.go @@ -49,7 +49,7 @@ func (c *Client) checkTasks() { torrent := c.tasks[id] ok := c.isSeedRatioLimitReached(r.IndexerID, torrent) if ok { - log.Infof("torrent file seed ratio reached, remove: %v", torrent.Name()) + log.Infof("torrent file seed ratio reached, remove: %v, current seed ratio: %v", torrent.Name(), torrent.SeedRatio()) torrent.Remove() delete(c.tasks, id) } else { @@ -138,7 +138,7 @@ func (c *Client) moveCompletedTask(id int) (err1 error) { //判断是否需要删除本地文件 ok := c.isSeedRatioLimitReached(r.IndexerID, torrent) if downloadclient.RemoveCompletedDownloads && ok { - log.Debugf("download complete,remove torrent and files related") + log.Debugf("download complete,remove torrent and files related, torrent: %v, seed ratio: %v", torrentName, torrent.SeedRatio()) delete(c.tasks, r.ID) torrent.Remove() } diff --git a/ui/lib/activity.dart b/ui/lib/activity.dart index a0d3c27..f80cb64 100644 --- a/ui/lib/activity.dart +++ b/ui/lib/activity.dart @@ -54,12 +54,15 @@ class _ActivityPageState extends ConsumerState ], ), Builder(builder: (context) { - var activitiesWatcher = ref.watch(activitiesDataProvider("active")); + AsyncValue>? activitiesWatcher; + if (selectedTab == 1) { activitiesWatcher = ref.watch(activitiesDataProvider("archive")); + } else if (selectedTab == 0) { + activitiesWatcher = ref.watch(activitiesDataProvider("active")); } - return activitiesWatcher.when( + return activitiesWatcher!.when( data: (activities) { return Flexible( child: ListView.builder( @@ -107,15 +110,15 @@ class _ActivityPageState extends ConsumerState ), ); }(), - title: - Text( (ac.sourceTitle ?? "")), + title: Text((ac.sourceTitle ?? "")), subtitle: Opacity( opacity: 0.7, child: Wrap( spacing: 10, children: [ Text("开始时间:${timeago.format(ac.date!)}"), - Text("大小:${(ac.size ?? 0).readableFileSize()}") + Text("大小:${(ac.size ?? 0).readableFileSize()}"), + ac.seedRatio > 0 ?Text("分享率:${ac.seedRatio}"): SizedBox() ], ), ), diff --git a/ui/lib/providers/activity.dart b/ui/lib/providers/activity.dart index eedac7c..9a562f8 100644 --- a/ui/lib/providers/activity.dart +++ b/ui/lib/providers/activity.dart @@ -69,7 +69,8 @@ class Activity { required this.status, required this.saved, required this.progress, - required this.size}); + required this.size, + required this.seedRatio}); final int? id; final int? mediaId; @@ -81,6 +82,7 @@ class Activity { final String? saved; final int? progress; final int? size; + final double seedRatio; factory Activity.fromJson(Map json) { return Activity( @@ -93,6 +95,7 @@ class Activity { status: json["status"], saved: json["saved"], progress: json["progress"], + seedRatio: json["seed_ratio"], size: json["size"]); } }