Debrid: Fix RealDebrid download handling
The torrent ID is no longer stored in the DebridManager. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
0caf8a8120
commit
96a6722e65
1 changed files with 25 additions and 16 deletions
|
|
@ -296,8 +296,9 @@ public class RealDebrid: PollingDebridSource {
|
||||||
|
|
||||||
// Wrapper function to fetch a download link from the API
|
// Wrapper function to fetch a download link from the API
|
||||||
public func getDownloadLink(magnet: Magnet, ia: DebridIA?, iaFile: DebridIAFile?, userTorrents: [DebridCloudTorrent] = []) async throws -> String {
|
public func getDownloadLink(magnet: Magnet, ia: DebridIA?, iaFile: DebridIAFile?, userTorrents: [DebridCloudTorrent] = []) async throws -> String {
|
||||||
let selectedMagnetId: String
|
var selectedMagnetId: String = ""
|
||||||
|
|
||||||
|
do {
|
||||||
// Don't queue a new job if the torrent already exists
|
// Don't queue a new job if the torrent already exists
|
||||||
if let existingTorrent = userTorrents.first(where: { $0.hash == magnet.hash && $0.status == "downloaded" }) {
|
if let existingTorrent = userTorrents.first(where: { $0.hash == magnet.hash && $0.status == "downloaded" }) {
|
||||||
selectedMagnetId = existingTorrent.torrentId
|
selectedMagnetId = existingTorrent.torrentId
|
||||||
|
|
@ -315,6 +316,14 @@ public class RealDebrid: PollingDebridSource {
|
||||||
let downloadLink = try await unrestrictLink(debridDownloadLink: torrentLink)
|
let downloadLink = try await unrestrictLink(debridDownloadLink: torrentLink)
|
||||||
|
|
||||||
return downloadLink
|
return downloadLink
|
||||||
|
} catch {
|
||||||
|
if case RealDebrid.RDError.EmptyTorrents = error, !selectedMagnetId.isEmpty {
|
||||||
|
try? await deleteTorrent(torrentId: selectedMagnetId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Re-raise the error to the calling function
|
||||||
|
throw error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds a magnet link to the user's RD account
|
// Adds a magnet link to the user's RD account
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue