Skip to content

Commit

Permalink
Make sure torrents get deleted on failed
Browse files Browse the repository at this point in the history
  • Loading branch information
sirrobot01 committed Dec 12, 2024
1 parent 4eb3539 commit 7359f28
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/debrid/debrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ func ProcessTorrent(d *DebridService, magnet *common.Magnet, a *arr.Arr, isSymli

dbt, err := db.SubmitMagnet(debridTorrent)
if err != nil || dbt.Id == "" {
if dbt != nil {
dbt.Delete()
}
logger.Printf("Error submitting magnet: %s", err)
continue
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/qbit/server/torrent_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func (s *Server) handleTorrentsAdd(w http.ResponseWriter, r *http.Request) {

if contentType == "multipart/form-data" {
files := r.MultipartForm.File["torrents"]
if len(files) == 0 {
s.logger.Printf("No files provided\n")
http.Error(w, "No files provided", http.StatusBadRequest)
return
}
for _, fileHeader := range files {
if err := s.qbit.AddTorrent(ctx, fileHeader, category); err != nil {
s.logger.Printf("Error adding torrent: %v\n", err)
Expand Down
1 change: 1 addition & 0 deletions pkg/qbit/shared/torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (q *QBit) ProcessFiles(torrent *Torrent, debridTorrent *debrid.Torrent, arr
dbT, err := debridTorrent.Debrid.CheckStatus(debridTorrent, isSymlink)
if err != nil {
q.logger.Printf("Error checking status: %v", err)
go debridTorrent.Delete()
q.MarkAsFailed(torrent)
_ = arr.Refresh()
return
Expand Down

0 comments on commit 7359f28

Please sign in to comment.