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