mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-07 02:27:40 +08:00
feat: better seeding status
This commit is contained in:
@@ -21,30 +21,35 @@ type Activity struct {
|
||||
|
||||
func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) {
|
||||
q := c.Query("status")
|
||||
his := s.db.GetHistories()
|
||||
var activities = make([]Activity, 0, len(his))
|
||||
for _, h := range his {
|
||||
if q == "archive" && (h.Status == history.StatusRunning || h.Status == history.StatusUploading) {
|
||||
continue //archived downloads
|
||||
}
|
||||
|
||||
a := Activity{
|
||||
History: h,
|
||||
}
|
||||
existInDownloadClient := false
|
||||
for id, task := range s.core.GetTasks() {
|
||||
if h.ID == id && task.Exists() {
|
||||
a.Progress = task.Progress()
|
||||
a.SeedRatio = float32(*task.SeedRatio())
|
||||
existInDownloadClient = true
|
||||
var activities = make([]Activity, 0)
|
||||
if q == "active" {
|
||||
his := s.db.GetRunningHistories()
|
||||
for _, h := range his {
|
||||
a := Activity{
|
||||
History: h,
|
||||
}
|
||||
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)
|
||||
}
|
||||
if q == "active" && !existInDownloadClient {
|
||||
continue
|
||||
}
|
||||
activities = append(activities, a)
|
||||
}
|
||||
} else {
|
||||
his := s.db.GetHistories()
|
||||
for _, h := range his {
|
||||
if h.Status == history.StatusRunning || h.Status == history.StatusUploading || h.Status == history.StatusSeeding {
|
||||
continue //archived downloads
|
||||
}
|
||||
|
||||
a := Activity{
|
||||
History: h,
|
||||
}
|
||||
activities = append(activities, a)
|
||||
}
|
||||
|
||||
}
|
||||
return activities, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ func (c *Client) Init() {
|
||||
}
|
||||
|
||||
func (c *Client) reloadTasks() {
|
||||
allTasks := c.db.GetHistories()
|
||||
allTasks := c.db.GetRunningHistories()
|
||||
for _, t := range allTasks {
|
||||
torrent, err := transmission.ReloadTorrent(t.Saved)
|
||||
if err != nil {
|
||||
@@ -78,8 +78,7 @@ func (c *Client) MustTMDB() *tmdb.Client {
|
||||
return t
|
||||
}
|
||||
|
||||
|
||||
func (c *Client) RemoveTaskAndTorrent(id int)error {
|
||||
func (c *Client) RemoveTaskAndTorrent(id int) error {
|
||||
torrent := c.tasks[id]
|
||||
if torrent != nil {
|
||||
if err := torrent.Remove(); err != nil {
|
||||
@@ -92,4 +91,4 @@ func (c *Client) RemoveTaskAndTorrent(id int)error {
|
||||
|
||||
func (c *Client) GetTasks() map[int]*Task {
|
||||
return c.tasks
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,23 +40,18 @@ func (c *Client) checkTasks() {
|
||||
if !t.Exists() {
|
||||
log.Infof("task no longer exists: %v", id)
|
||||
|
||||
if r.Status == history.StatusRunning || r.Status == history.StatusUploading {
|
||||
log.Warnf("task is running but no longer available in download client, mark as fail, task name: %s", r.SourceTitle)
|
||||
c.db.SetHistoryStatus(id, history.StatusFail)
|
||||
}
|
||||
|
||||
delete(c.tasks, id)
|
||||
continue
|
||||
}
|
||||
log.Infof("task (%s) percentage done: %d%%", t.Name(), t.Progress())
|
||||
if t.Progress() == 100 {
|
||||
|
||||
if r.Status == history.StatusSuccess {
|
||||
if r.Status == history.StatusSeeding {
|
||||
//task already success, check seed ratio
|
||||
torrent := c.tasks[id]
|
||||
ok := c.isSeedRatioLimitReached(r.IndexerID, torrent)
|
||||
if ok {
|
||||
log.Infof("torrent file seed ratio reached, remove: %v, current seed ratio: %v", torrent.Name(), torrent.SeedRatio())
|
||||
log.Infof("torrent file seed ratio reached, remove: %v, current seed ratio: %v", torrent.Name(), *torrent.SeedRatio())
|
||||
torrent.Remove()
|
||||
delete(c.tasks, id)
|
||||
} else {
|
||||
@@ -104,7 +99,7 @@ func (c *Client) moveCompletedTask(id int) (err1 error) {
|
||||
} else {
|
||||
c.db.SetSeasonAllEpisodeStatus(r.MediaID, seasonNum, episode.StatusMissing)
|
||||
}
|
||||
c.sendMsg(fmt.Sprintf(message.ProcessingFailed, err))
|
||||
c.sendMsg(fmt.Sprintf(message.ProcessingFailed, err1))
|
||||
if downloadclient.RemoveFailedDownloads {
|
||||
log.Debugf("task failed, remove failed torrent and files related")
|
||||
delete(c.tasks, r.ID)
|
||||
@@ -134,7 +129,7 @@ func (c *Client) moveCompletedTask(id int) (err1 error) {
|
||||
return errors.Wrap(err, "move file")
|
||||
}
|
||||
|
||||
c.db.SetHistoryStatus(r.ID, history.StatusSuccess)
|
||||
c.db.SetHistoryStatus(r.ID, history.StatusSeeding)
|
||||
if r.EpisodeID != 0 {
|
||||
c.db.SetEpisodeStatus(r.EpisodeID, episode.StatusDownloaded)
|
||||
} else {
|
||||
@@ -145,7 +140,8 @@ 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, torrent: %v, seed ratio: %v", torrentName, torrent.SeedRatio())
|
||||
log.Debugf("download complete,remove torrent and files related, torrent: %v, seed ratio: %v", torrentName, *torrent.SeedRatio())
|
||||
c.db.SetHistoryStatus(r.ID, history.StatusSuccess)
|
||||
delete(c.tasks, r.ID)
|
||||
torrent.Remove()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user