mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-09 03:27:39 +08:00
basic find download ability
This commit is contained in:
@@ -5,6 +5,9 @@ import (
|
||||
"polaris/log"
|
||||
"polaris/pkg/tmdb"
|
||||
|
||||
"github.com/hekmon/transmissionrpc"
|
||||
"github.com/robfig/cron"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@@ -12,18 +15,34 @@ import (
|
||||
func NewServer(db *db.Client) *Server {
|
||||
r := gin.Default()
|
||||
return &Server{
|
||||
r: r,
|
||||
db: db,
|
||||
r: r,
|
||||
db: db,
|
||||
cron: cron.New(),
|
||||
tasks: make(map[string]*transmissionrpc.Torrent),
|
||||
}
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
r *gin.Engine
|
||||
db *db.Client
|
||||
r *gin.Engine
|
||||
db *db.Client
|
||||
cron *cron.Cron
|
||||
language string
|
||||
tasks map[string]*transmissionrpc.Torrent
|
||||
}
|
||||
|
||||
func (s *Server) scheduler() {
|
||||
s.cron.AddFunc("@every 1m", s.checkTasks)
|
||||
}
|
||||
|
||||
func (s *Server) checkTasks() {
|
||||
for name, t := range s.tasks {
|
||||
log.Infof("task %s percentage done: %f", name, *t.PercentDone)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) Serve() error {
|
||||
s.scheduler()
|
||||
|
||||
api := s.r.Group("/api/v1")
|
||||
|
||||
setting := api.Group("/setting")
|
||||
@@ -38,12 +57,21 @@ func (s *Server) Serve() error {
|
||||
tv.POST("/watchlist", HttpHandler(s.AddWatchlist))
|
||||
tv.GET("/watchlist", HttpHandler(s.GetWatchlist))
|
||||
}
|
||||
indexer := api.Group("/indexer")
|
||||
{
|
||||
indexer.POST("/add", HttpHandler(s.AddTorznabInfo))
|
||||
indexer.POST("/download", HttpHandler(s.SearchAndDownload))
|
||||
}
|
||||
|
||||
downloader := api.Group("/downloader")
|
||||
{
|
||||
downloader.POST("/add", HttpHandler(s.AddDownloadClient))
|
||||
}
|
||||
|
||||
s.language = s.db.GetLanguage()
|
||||
return s.r.Run(":8080")
|
||||
}
|
||||
|
||||
|
||||
func (s *Server) TMDB() (*tmdb.Client, error) {
|
||||
api := s.db.GetSetting(db.SettingTmdbApiKey)
|
||||
if api == "" {
|
||||
@@ -59,4 +87,3 @@ func (s *Server) MustTMDB() *tmdb.Client {
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user