diff --git a/Ferrite/API/AllDebridWrapper.swift b/Ferrite/API/AllDebridWrapper.swift index 0be8254..30fcb31 100644 --- a/Ferrite/API/AllDebridWrapper.swift +++ b/Ferrite/API/AllDebridWrapper.swift @@ -11,6 +11,7 @@ class AllDebrid: PollingDebridSource, ObservableObject { let id = "AllDebrid" let abbreviation = "AD" let website = "https://alldebrid.com" + let cachedStatus: [String] = ["Ready"] var authTask: Task? @Published var authProcessing: Bool = false @@ -224,7 +225,7 @@ class AllDebrid: PollingDebridSource, ObservableObject { func getRestrictedFile(magnet: Magnet, ia: DebridIA?, iaFile: DebridIAFile?) async throws -> (restrictedFile: DebridIAFile?, newIA: DebridIA?) { let selectedMagnetId: String - if let existingMagnet = cloudMagnets.first(where: { $0.hash == magnet.hash && $0.status == "Ready" }) { + if let existingMagnet = cloudMagnets.first(where: { $0.hash == magnet.hash && cachedStatus.contains($0.status) }) { selectedMagnetId = existingMagnet.id } else { let magnetId = try await addMagnet(magnet: magnet) @@ -317,7 +318,7 @@ class AllDebrid: PollingDebridSource, ObservableObject { DebridCloudMagnet( id: String(magnetResponse.id), fileName: magnetResponse.filename, - status: magnetResponse.status == "Ready" ? "downloaded" : magnetResponse.status, + status: magnetResponse.status, hash: magnetResponse.hash, links: magnetResponse.links.map(\.link) ) diff --git a/Ferrite/API/OffCloudWrapper.swift b/Ferrite/API/OffCloudWrapper.swift index c1fabfc..9311a47 100644 --- a/Ferrite/API/OffCloudWrapper.swift +++ b/Ferrite/API/OffCloudWrapper.swift @@ -14,6 +14,7 @@ class OffCloud: DebridSource, ObservableObject { let description: String? = "OffCloud is a debrid service that is used for downloads and media playback. " + "You must pay to access this service. \n\n" + "This service does not inform if a magnet link is a batch before downloading." + let cachedStatus: [String] = ["downloaded"] @Published var authProcessing: Bool = false var isLoggedIn: Bool { @@ -143,12 +144,12 @@ class OffCloud: DebridSource, ObservableObject { let selectedCloudMagnet: DebridCloudMagnet // Don't queue a new job if the magnet already exists in the user's account - if let existingCloudMagnet = cloudMagnets.first(where: { $0.hash == magnet.hash && $0.status == "downloaded" }) { + if let existingCloudMagnet = cloudMagnets.first(where: { $0.hash == magnet.hash && cachedStatus.contains($0.status) }) { selectedCloudMagnet = existingCloudMagnet } else { let cloudDownloadResponse = try await offcloudDownload(magnet: magnet) - guard cloudDownloadResponse.status == "downloaded" else { + guard cachedStatus.contains(cloudDownloadResponse.status) else { throw DebridError.IsCaching } diff --git a/Ferrite/API/RealDebridWrapper.swift b/Ferrite/API/RealDebridWrapper.swift index c64cbf1..b1445f4 100644 --- a/Ferrite/API/RealDebridWrapper.swift +++ b/Ferrite/API/RealDebridWrapper.swift @@ -11,6 +11,7 @@ class RealDebrid: PollingDebridSource, ObservableObject { let id = "RealDebrid" let abbreviation = "RD" let website = "https://real-debrid.com" + let cachedStatus: [String] = ["downloaded"] var authTask: Task? @Published var authProcessing: Bool = false diff --git a/Ferrite/API/TorBoxWrapper.swift b/Ferrite/API/TorBoxWrapper.swift index c51e6ba..3894969 100644 --- a/Ferrite/API/TorBoxWrapper.swift +++ b/Ferrite/API/TorBoxWrapper.swift @@ -13,6 +13,7 @@ class TorBox: DebridSource, ObservableObject { let website = "https://torbox.app" let description: String? = "TorBox is a debrid service that is used for downloads and media playback with seeding. " + "Both free and paid plans are available." + let cachedStatus: [String] = ["cached", "completed"] @Published var authProcessing: Bool = false var isLoggedIn: Bool { @@ -155,7 +156,7 @@ class TorBox: DebridSource, ObservableObject { } // If the user magnet isn't saved, it's considered as caching - guard filteredCloudMagnet.downloadState == "cached" || filteredCloudMagnet.downloadState == "completed" else { + guard cachedStatus.contains(filteredCloudMagnet.downloadState) else { throw DebridError.IsCaching } @@ -245,7 +246,7 @@ class TorBox: DebridSource, ObservableObject { DebridCloudMagnet( id: String(cloudMagnet.id), fileName: cloudMagnet.name, - status: cloudMagnet.downloadState == "cached" || cloudMagnet.downloadState == "completed" ? "downloaded" : cloudMagnet.downloadState, + status: cloudMagnet.downloadState, hash: cloudMagnet.hash, links: cloudMagnet.files.map { String($0.id) } ) diff --git a/Ferrite/Protocols/Debrid.swift b/Ferrite/Protocols/Debrid.swift index d7ecbff..c325bb8 100644 --- a/Ferrite/Protocols/Debrid.swift +++ b/Ferrite/Protocols/Debrid.swift @@ -14,6 +14,7 @@ protocol DebridSource: AnyObservableObject { var abbreviation: String { get } var website: String { get } var description: String? { get } + var cachedStatus: [String] { get } // Auth variables var authProcessing: Bool { get set } @@ -59,6 +60,10 @@ extension DebridSource { var description: String? { nil } + + var cachedStatus: [String] { + [] + } } protocol PollingDebridSource: DebridSource { diff --git a/Ferrite/Views/ComponentViews/Library/Cloud/CloudMagnetView.swift b/Ferrite/Views/ComponentViews/Library/Cloud/CloudMagnetView.swift index 8da3066..870f63a 100644 --- a/Ferrite/Views/ComponentViews/Library/Cloud/CloudMagnetView.swift +++ b/Ferrite/Views/ComponentViews/Library/Cloud/CloudMagnetView.swift @@ -22,7 +22,7 @@ struct CloudMagnetView: View { searchText.isEmpty ? true : $0.fileName.lowercased().contains(searchText.lowercased()) }, id: \.self) { cloudMagnet in Button { - if cloudMagnet.status == "downloaded", !cloudMagnet.links.isEmpty { + if debridSource.cachedStatus.contains(cloudMagnet.status), !cloudMagnet.links.isEmpty { navModel.resultFromCloud = true navModel.selectedTitle = cloudMagnet.fileName diff --git a/Ferrite/Views/ComponentViews/Library/DebridCloudView.swift b/Ferrite/Views/ComponentViews/Library/DebridCloudView.swift index 63a5932..412a829 100644 --- a/Ferrite/Views/ComponentViews/Library/DebridCloudView.swift +++ b/Ferrite/Views/ComponentViews/Library/DebridCloudView.swift @@ -16,13 +16,8 @@ struct DebridCloudView: View { var body: some View { List { - if !debridSource.cloudDownloads.isEmpty { - CloudDownloadView(debridSource: debridSource, searchText: $searchText) - } - - if !debridSource.cloudMagnets.isEmpty { - CloudMagnetView(debridSource: debridSource, searchText: $searchText) - } + CloudDownloadView(debridSource: debridSource, searchText: $searchText) + CloudMagnetView(debridSource: debridSource, searchText: $searchText) } .listStyle(.plain) .task {