feat: add seed ratio display

This commit is contained in:
Simon Ding
2024-08-11 20:41:26 +08:00
parent 5c6ac2c430
commit 5b70badb50
4 changed files with 17 additions and 9 deletions

View File

@@ -15,7 +15,8 @@ import (
type Activity struct { type Activity struct {
*ent.History *ent.History
Progress int `json:"progress"` Progress int `json:"progress"`
SeedRatio float32 `json:"seed_ratio"`
} }
func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) { 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() { for id, task := range s.core.GetTasks() {
if h.ID == id && task.Exists() { if h.ID == id && task.Exists() {
a.Progress = task.Progress() a.Progress = task.Progress()
a.SeedRatio = float32(*task.SeedRatio())
} }
} }
activities = append(activities, a) activities = append(activities, a)

View File

@@ -49,7 +49,7 @@ func (c *Client) checkTasks() {
torrent := c.tasks[id] torrent := c.tasks[id]
ok := c.isSeedRatioLimitReached(r.IndexerID, torrent) ok := c.isSeedRatioLimitReached(r.IndexerID, torrent)
if ok { 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() torrent.Remove()
delete(c.tasks, id) delete(c.tasks, id)
} else { } else {
@@ -138,7 +138,7 @@ func (c *Client) moveCompletedTask(id int) (err1 error) {
//判断是否需要删除本地文件 //判断是否需要删除本地文件
ok := c.isSeedRatioLimitReached(r.IndexerID, torrent) ok := c.isSeedRatioLimitReached(r.IndexerID, torrent)
if downloadclient.RemoveCompletedDownloads && ok { 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) delete(c.tasks, r.ID)
torrent.Remove() torrent.Remove()
} }

View File

@@ -54,12 +54,15 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
], ],
), ),
Builder(builder: (context) { Builder(builder: (context) {
var activitiesWatcher = ref.watch(activitiesDataProvider("active")); AsyncValue<List<Activity>>? activitiesWatcher;
if (selectedTab == 1) { if (selectedTab == 1) {
activitiesWatcher = ref.watch(activitiesDataProvider("archive")); activitiesWatcher = ref.watch(activitiesDataProvider("archive"));
} else if (selectedTab == 0) {
activitiesWatcher = ref.watch(activitiesDataProvider("active"));
} }
return activitiesWatcher.when( return activitiesWatcher!.when(
data: (activities) { data: (activities) {
return Flexible( return Flexible(
child: ListView.builder( child: ListView.builder(
@@ -107,15 +110,15 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
), ),
); );
}(), }(),
title: title: Text((ac.sourceTitle ?? "")),
Text( (ac.sourceTitle ?? "")),
subtitle: Opacity( subtitle: Opacity(
opacity: 0.7, opacity: 0.7,
child: Wrap( child: Wrap(
spacing: 10, spacing: 10,
children: [ children: [
Text("开始时间:${timeago.format(ac.date!)}"), Text("开始时间:${timeago.format(ac.date!)}"),
Text("大小:${(ac.size ?? 0).readableFileSize()}") Text("大小:${(ac.size ?? 0).readableFileSize()}"),
ac.seedRatio > 0 ?Text("分享率:${ac.seedRatio}"): SizedBox()
], ],
), ),
), ),

View File

@@ -69,7 +69,8 @@ class Activity {
required this.status, required this.status,
required this.saved, required this.saved,
required this.progress, required this.progress,
required this.size}); required this.size,
required this.seedRatio});
final int? id; final int? id;
final int? mediaId; final int? mediaId;
@@ -81,6 +82,7 @@ class Activity {
final String? saved; final String? saved;
final int? progress; final int? progress;
final int? size; final int? size;
final double seedRatio;
factory Activity.fromJson(Map<String, dynamic> json) { factory Activity.fromJson(Map<String, dynamic> json) {
return Activity( return Activity(
@@ -93,6 +95,7 @@ class Activity {
status: json["status"], status: json["status"],
saved: json["saved"], saved: json["saved"],
progress: json["progress"], progress: json["progress"],
seedRatio: json["seed_ratio"],
size: json["size"]); size: json["size"]);
} }
} }