fix reinsert torrent error
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
site_name: Decypharr
|
site_name: Decypharr
|
||||||
site_url: https://sirrobot01.github.io/decypharr
|
site_url: https://sirrobot01.github.io/debrid-blackhole
|
||||||
site_description: QbitTorrent with Debrid Support
|
site_description: QbitTorrent with Debrid Support
|
||||||
repo_url: https://github.com/sirrobot01/decypharr
|
repo_url: https://github.com/sirrobot01/debrid-blackhole
|
||||||
repo_name: sirrobot01/decypharr
|
repo_name: sirrobot01/debrid-blackhole
|
||||||
edit_uri: blob/main/docs
|
edit_uri: blob/main/docs
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -552,7 +552,7 @@ func (c *Cache) ProcessTorrent(t *types.Torrent, refreshRclone bool) error {
|
|||||||
|
|
||||||
if !isComplete(t.Files) {
|
if !isComplete(t.Files) {
|
||||||
c.logger.Debug().Msgf("Torrent %s is still not complete. Triggering a reinsert(disabled)", t.Id)
|
c.logger.Debug().Msgf("Torrent %s is still not complete. Triggering a reinsert(disabled)", t.Id)
|
||||||
//ct, err := c.reInsertTorrent(t)
|
//err := c.reInsertTorrent(t)
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// c.logger.Error().Err(err).Msgf("Failed to reinsert torrent %s", t.Id)
|
// c.logger.Error().Err(err).Msgf("Failed to reinsert torrent %s", t.Id)
|
||||||
// return err
|
// return err
|
||||||
@@ -605,8 +605,7 @@ func (c *Cache) GetDownloadLink(torrentId, filename, fileLink string) string {
|
|||||||
if file.Link == "" {
|
if file.Link == "" {
|
||||||
c.logger.Debug().Msgf("File link is empty for %s. Release is probably nerfed", filename)
|
c.logger.Debug().Msgf("File link is empty for %s. Release is probably nerfed", filename)
|
||||||
// Try to reinsert the torrent?
|
// Try to reinsert the torrent?
|
||||||
ct, err := c.reInsertTorrent(ct)
|
if err := c.reInsertTorrent(ct); err != nil {
|
||||||
if err != nil {
|
|
||||||
c.logger.Error().Err(err).Msgf("Failed to reinsert torrent %s", ct.Name)
|
c.logger.Error().Err(err).Msgf("Failed to reinsert torrent %s", ct.Name)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -619,7 +618,7 @@ func (c *Cache) GetDownloadLink(torrentId, filename, fileLink string) string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, request.HosterUnavailableError) {
|
if errors.Is(err, request.HosterUnavailableError) {
|
||||||
c.logger.Error().Err(err).Msgf("Hoster is unavailable. Triggering repair for %s", ct.Name)
|
c.logger.Error().Err(err).Msgf("Hoster is unavailable. Triggering repair for %s", ct.Name)
|
||||||
ct, err := c.reInsertTorrent(ct)
|
err := c.reInsertTorrent(ct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Error().Err(err).Msgf("Failed to reinsert torrent %s", ct.Name)
|
c.logger.Error().Err(err).Msgf("Failed to reinsert torrent %s", ct.Name)
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
@@ -79,9 +79,7 @@ func (c *Cache) repairWorker() {
|
|||||||
switch req.Type {
|
switch req.Type {
|
||||||
case RepairTypeReinsert:
|
case RepairTypeReinsert:
|
||||||
c.logger.Debug().Str("torrentId", torrentId).Msg("Reinserting torrent")
|
c.logger.Debug().Str("torrentId", torrentId).Msg("Reinserting torrent")
|
||||||
var err error
|
if err := c.reInsertTorrent(cachedTorrent); err != nil {
|
||||||
cachedTorrent, err = c.reInsertTorrent(cachedTorrent)
|
|
||||||
if err != nil {
|
|
||||||
c.logger.Error().Err(err).Str("torrentId", cachedTorrent.Id).Msg("Failed to reinsert torrent")
|
c.logger.Error().Err(err).Str("torrentId", cachedTorrent.Id).Msg("Failed to reinsert torrent")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -96,11 +94,11 @@ func (c *Cache) repairWorker() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) reInsertTorrent(ct *CachedTorrent) (*CachedTorrent, error) {
|
func (c *Cache) reInsertTorrent(ct *CachedTorrent) error {
|
||||||
// Check if Magnet is not empty, if empty, reconstruct the magnet
|
// Check if Magnet is not empty, if empty, reconstruct the magnet
|
||||||
torrent := ct.Torrent
|
torrent := ct.Torrent
|
||||||
if _, ok := c.repairsInProgress.Load(torrent.Id); ok {
|
if _, ok := c.repairsInProgress.Load(torrent.Id); ok {
|
||||||
return ct, fmt.Errorf("repair already in progress for torrent %s", torrent.Id)
|
return fmt.Errorf("repair already in progress for torrent %s", torrent.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if torrent.Magnet == nil {
|
if torrent.Magnet == nil {
|
||||||
@@ -121,12 +119,12 @@ func (c *Cache) reInsertTorrent(ct *CachedTorrent) (*CachedTorrent, error) {
|
|||||||
torrent, err = c.client.SubmitMagnet(torrent)
|
torrent, err = c.client.SubmitMagnet(torrent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Remove the old torrent from the cache and debrid service
|
// Remove the old torrent from the cache and debrid service
|
||||||
return nil, fmt.Errorf("failed to submit magnet: %w", err)
|
return fmt.Errorf("failed to submit magnet: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the torrent was submitted
|
// Check if the torrent was submitted
|
||||||
if torrent == nil || torrent.Id == "" {
|
if torrent == nil || torrent.Id == "" {
|
||||||
return nil, fmt.Errorf("failed to submit magnet: empty torrent")
|
return fmt.Errorf("failed to submit magnet: empty torrent")
|
||||||
}
|
}
|
||||||
torrent.DownloadUncached = false // Set to false, avoid re-downloading
|
torrent.DownloadUncached = false // Set to false, avoid re-downloading
|
||||||
torrent, err = c.client.CheckStatus(torrent, true)
|
torrent, err = c.client.CheckStatus(torrent, true)
|
||||||
@@ -134,11 +132,11 @@ func (c *Cache) reInsertTorrent(ct *CachedTorrent) (*CachedTorrent, error) {
|
|||||||
// Torrent is likely in progress
|
// Torrent is likely in progress
|
||||||
_ = c.DeleteTorrent(torrent.Id)
|
_ = c.DeleteTorrent(torrent.Id)
|
||||||
|
|
||||||
return nil, fmt.Errorf("failed to check status: %w", err)
|
return fmt.Errorf("failed to check status: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if torrent == nil {
|
if torrent == nil {
|
||||||
return nil, fmt.Errorf("failed to check status: empty torrent")
|
return fmt.Errorf("failed to check status: empty torrent")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the torrent in the cache
|
// Update the torrent in the cache
|
||||||
@@ -147,20 +145,18 @@ func (c *Cache) reInsertTorrent(ct *CachedTorrent) (*CachedTorrent, error) {
|
|||||||
if f.Link == "" {
|
if f.Link == "" {
|
||||||
// Delete the new torrent
|
// Delete the new torrent
|
||||||
_ = c.DeleteTorrent(torrent.Id)
|
_ = c.DeleteTorrent(torrent.Id)
|
||||||
return nil, fmt.Errorf("failed to reinsert torrent: empty link")
|
return fmt.Errorf("failed to reinsert torrent: empty link")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
addedOn = time.Now()
|
addedOn = time.Now()
|
||||||
}
|
}
|
||||||
ct = &CachedTorrent{
|
ct.Torrent = torrent
|
||||||
Torrent: torrent,
|
ct.IsComplete = len(torrent.Files) > 0
|
||||||
IsComplete: len(torrent.Files) > 0,
|
ct.AddedOn = addedOn
|
||||||
AddedOn: addedOn,
|
|
||||||
}
|
|
||||||
c.setTorrent(ct)
|
c.setTorrent(ct)
|
||||||
c.refreshListings()
|
c.refreshListings()
|
||||||
return ct, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) resetInvalidLinks() {
|
func (c *Cache) resetInvalidLinks() {
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/go-chi/chi/v5/middleware"
|
"github.com/go-chi/chi/v5/middleware"
|
||||||
"github.com/goccy/go-json"
|
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/sirrobot01/decypharr/internal/config"
|
"github.com/sirrobot01/decypharr/internal/config"
|
||||||
"github.com/sirrobot01/decypharr/internal/logger"
|
"github.com/sirrobot01/decypharr/internal/logger"
|
||||||
|
"github.com/sirrobot01/decypharr/internal/request"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -126,10 +126,5 @@ func (s *Server) getStats(w http.ResponseWriter, r *http.Request) {
|
|||||||
// System info
|
// System info
|
||||||
"num_cpu": runtime.NumCPU(),
|
"num_cpu": runtime.NumCPU(),
|
||||||
}
|
}
|
||||||
|
request.JSONResponse(w, stats, http.StatusOK)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
if err := json.NewEncoder(w).Encode(stats); err != nil {
|
|
||||||
s.logger.Error().Err(err).Msg("Failed to encode stats")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -511,8 +511,7 @@ func (ui *Handler) handleUpdateConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return success
|
// Return success
|
||||||
w.WriteHeader(http.StatusOK)
|
request.JSONResponse(w, map[string]string{"status": "success"}, http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(map[string]string{"status": "success"})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *Handler) handleGetRepairJobs(w http.ResponseWriter, r *http.Request) {
|
func (ui *Handler) handleGetRepairJobs(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user