Changelog 0.3.2
This commit is contained in:
+2
-2
@@ -8,8 +8,8 @@ import (
|
||||
"goBlack/pkg/qbit/server"
|
||||
)
|
||||
|
||||
func Start(ctx context.Context, config *common.Config, deb *debrid.DebridService, cache *common.Cache) error {
|
||||
srv := server.NewServer(config, deb, cache)
|
||||
func Start(ctx context.Context, config *common.Config, deb *debrid.DebridService) error {
|
||||
srv := server.NewServer(config, deb)
|
||||
if err := srv.Start(ctx); err != nil {
|
||||
return fmt.Errorf("failed to start qbit server: %w", err)
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ func (s *Server) Routes(r chi.Router) http.Handler {
|
||||
r.Get("/episodes/{contentId}", s.handleEpisodes)
|
||||
r.Post("/add", s.handleAddContent)
|
||||
r.Get("/search", s.handleSearch)
|
||||
r.Get("/cached", s.handleCheckCached)
|
||||
})
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ type Server struct {
|
||||
debug bool
|
||||
}
|
||||
|
||||
func NewServer(config *common.Config, deb *debrid.DebridService, cache *common.Cache) *Server {
|
||||
func NewServer(config *common.Config, deb *debrid.DebridService) *Server {
|
||||
logger := common.NewLogger("QBit", os.Stdout)
|
||||
q := shared.NewQBit(config, deb, cache, logger)
|
||||
q := shared.NewQBit(config, deb, logger)
|
||||
return &Server{
|
||||
qbit: q,
|
||||
logger: logger,
|
||||
|
||||
@@ -5,8 +5,10 @@ import (
|
||||
"encoding/json"
|
||||
"goBlack/common"
|
||||
"goBlack/pkg/arr"
|
||||
"goBlack/pkg/debrid"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type AddRequest struct {
|
||||
@@ -112,3 +114,36 @@ func (s *Server) handleAddContent(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
common.JSONResponse(w, importReq, http.StatusOK)
|
||||
}
|
||||
|
||||
func (s *Server) handleCheckCached(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_hashes := r.URL.Query().Get("hash")
|
||||
if _hashes == "" {
|
||||
http.Error(w, "No hashes provided", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
hashes := strings.Split(_hashes, ",")
|
||||
if len(hashes) == 0 {
|
||||
http.Error(w, "No hashes provided", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
db := r.URL.Query().Get("debrid")
|
||||
var deb debrid.Service
|
||||
if db == "" {
|
||||
// use the first debrid
|
||||
deb = s.qbit.Debrid.Get()
|
||||
} else {
|
||||
deb = s.qbit.Debrid.GetByName(db)
|
||||
}
|
||||
if deb == nil {
|
||||
http.Error(w, "Invalid debrid", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
res := deb.IsAvailable(hashes)
|
||||
result := make(map[string]bool)
|
||||
for _, h := range hashes {
|
||||
_, exists := res[h]
|
||||
result[h] = exists
|
||||
}
|
||||
common.JSONResponse(w, result, http.StatusOK)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ type QBit struct {
|
||||
DownloadFolder string `json:"download_folder"`
|
||||
Categories []string `json:"categories"`
|
||||
Debrid *debrid.DebridService
|
||||
cache *common.Cache
|
||||
Storage *TorrentStorage
|
||||
debug bool
|
||||
logger *log.Logger
|
||||
@@ -24,7 +23,7 @@ type QBit struct {
|
||||
RefreshInterval int
|
||||
}
|
||||
|
||||
func NewQBit(config *common.Config, deb *debrid.DebridService, cache *common.Cache, logger *log.Logger) *QBit {
|
||||
func NewQBit(config *common.Config, deb *debrid.DebridService, logger *log.Logger) *QBit {
|
||||
cfg := config.QBitTorrent
|
||||
port := cmp.Or(cfg.Port, os.Getenv("QBIT_PORT"), "8182")
|
||||
refreshInterval := cmp.Or(cfg.RefreshInterval, 10)
|
||||
@@ -36,7 +35,6 @@ func NewQBit(config *common.Config, deb *debrid.DebridService, cache *common.Cac
|
||||
DownloadFolder: cfg.DownloadFolder,
|
||||
Categories: cfg.Categories,
|
||||
Debrid: deb,
|
||||
cache: cache,
|
||||
debug: cfg.Debug,
|
||||
Storage: NewTorrentStorage("torrents.json"),
|
||||
logger: logger,
|
||||
|
||||
@@ -92,7 +92,7 @@ func (q *QBit) ProcessFiles(torrent *Torrent, debridTorrent *debrid.Torrent, arr
|
||||
for debridTorrent.Status != "downloaded" {
|
||||
progress := debridTorrent.Progress
|
||||
q.logger.Printf("%s Download Progress: %.2f%%", debridTorrent.Debrid.GetName(), progress)
|
||||
time.Sleep(5 * time.Second)
|
||||
time.Sleep(4 * time.Second)
|
||||
dbT, err := debridTorrent.Debrid.CheckStatus(debridTorrent, isSymlink)
|
||||
if err != nil {
|
||||
q.logger.Printf("Error checking status: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user