feat: activity

This commit is contained in:
Simon Ding
2024-07-12 15:54:46 +08:00
parent 799884f73c
commit 5257b07888
6 changed files with 63 additions and 24 deletions

View File

@@ -1,7 +1,42 @@
package server
import "github.com/gin-gonic/gin"
import (
"polaris/log"
"strconv"
func (s *Server) GetRunningActivities(c *gin.Context) (interface{}, error) {
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)
func (s *Server) GetAllActivities(c *gin.Context) (interface{}, error) {
his := s.db.GetHistories()
return his, nil
}
func (s *Server) RemoveActivity(c *gin.Context) (interface{}, error) {
ids := c.Param("id")
id, err := strconv.Atoi(ids)
if err != nil {
return nil, errors.Wrap(err, "convert")
}
his := s.db.GetHistory(id)
if his == nil {
log.Errorf("no record of id: %d", id)
return nil, nil
}
torrent := s.tasks[his.ID]
if torrent != nil {
if err := torrent.Remove(true); err != nil {
return nil, errors.Wrap(err, "remove torrent")
}
delete(s.tasks, his.ID)
}
err = s.db.DeleteHistory(id)
if err != nil {
return nil, errors.Wrap(err, "db")
}
log.Infof("history record successful deleted: %v", his.SourceTitle)
return nil, nil
}
}

View File

@@ -30,7 +30,7 @@ func (s *Server) checkTasks() {
log.Infof("task (%s) percentage done: %d%%", t.Name(), t.Progress())
if t.Progress() == 100 {
log.Infof("task is done: %v", t.Name())
s.moveCompletedTask(id)
go s.moveCompletedTask(id)
}
}
}
@@ -38,6 +38,11 @@ func (s *Server) checkTasks() {
func (s *Server) moveCompletedTask(id int) error {
torrent := s.tasks[id]
r := s.db.GetHistory(id)
s.db.SetHistoryComplete(r.ID)
tt := s.tasks[r.ID]
tt.Remove(false)
delete(s.tasks, r.ID)
series := s.db.GetSeriesDetails(r.SeriesID)
st := s.db.GetStorage(series.StorageID)
if st.Implementation == db.ImplWebdav {

View File

@@ -52,6 +52,11 @@ func (s *Server) Serve() error {
setting.POST("/auth", HttpHandler(s.EnableAuth))
setting.GET("/auth", HttpHandler(s.GetAuthSetting))
}
activity := api.Group("/activity")
{
activity.GET("/", HttpHandler(s.GetAllActivities))
activity.DELETE("/:id", HttpHandler(s.RemoveActivity))
}
tv := api.Group("/tv")
{