Debrid: Use universal cached IDs
Different services can send different statuses for if a file is cached or not. Therefore, make this scoped to the debrid service rather than expecting everything to state "downloaded". Also it feels pretty blank if the disclosure groups are gone when a cloud array is empty, so remove those checks. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
78f2aff25b
commit
70b628b608
7 changed files with 18 additions and 14 deletions
|
|
@ -11,6 +11,7 @@ class AllDebrid: PollingDebridSource, ObservableObject {
|
||||||
let id = "AllDebrid"
|
let id = "AllDebrid"
|
||||||
let abbreviation = "AD"
|
let abbreviation = "AD"
|
||||||
let website = "https://alldebrid.com"
|
let website = "https://alldebrid.com"
|
||||||
|
let cachedStatus: [String] = ["Ready"]
|
||||||
var authTask: Task<Void, Error>?
|
var authTask: Task<Void, Error>?
|
||||||
|
|
||||||
@Published var authProcessing: Bool = false
|
@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?) {
|
func getRestrictedFile(magnet: Magnet, ia: DebridIA?, iaFile: DebridIAFile?) async throws -> (restrictedFile: DebridIAFile?, newIA: DebridIA?) {
|
||||||
let selectedMagnetId: String
|
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
|
selectedMagnetId = existingMagnet.id
|
||||||
} else {
|
} else {
|
||||||
let magnetId = try await addMagnet(magnet: magnet)
|
let magnetId = try await addMagnet(magnet: magnet)
|
||||||
|
|
@ -317,7 +318,7 @@ class AllDebrid: PollingDebridSource, ObservableObject {
|
||||||
DebridCloudMagnet(
|
DebridCloudMagnet(
|
||||||
id: String(magnetResponse.id),
|
id: String(magnetResponse.id),
|
||||||
fileName: magnetResponse.filename,
|
fileName: magnetResponse.filename,
|
||||||
status: magnetResponse.status == "Ready" ? "downloaded" : magnetResponse.status,
|
status: magnetResponse.status,
|
||||||
hash: magnetResponse.hash,
|
hash: magnetResponse.hash,
|
||||||
links: magnetResponse.links.map(\.link)
|
links: magnetResponse.links.map(\.link)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ class OffCloud: DebridSource, ObservableObject {
|
||||||
let description: String? = "OffCloud is a debrid service that is used for downloads and media playback. " +
|
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" +
|
"You must pay to access this service. \n\n" +
|
||||||
"This service does not inform if a magnet link is a batch before downloading."
|
"This service does not inform if a magnet link is a batch before downloading."
|
||||||
|
let cachedStatus: [String] = ["downloaded"]
|
||||||
|
|
||||||
@Published var authProcessing: Bool = false
|
@Published var authProcessing: Bool = false
|
||||||
var isLoggedIn: Bool {
|
var isLoggedIn: Bool {
|
||||||
|
|
@ -143,12 +144,12 @@ class OffCloud: DebridSource, ObservableObject {
|
||||||
let selectedCloudMagnet: DebridCloudMagnet
|
let selectedCloudMagnet: DebridCloudMagnet
|
||||||
|
|
||||||
// Don't queue a new job if the magnet already exists in the user's account
|
// 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
|
selectedCloudMagnet = existingCloudMagnet
|
||||||
} else {
|
} else {
|
||||||
let cloudDownloadResponse = try await offcloudDownload(magnet: magnet)
|
let cloudDownloadResponse = try await offcloudDownload(magnet: magnet)
|
||||||
|
|
||||||
guard cloudDownloadResponse.status == "downloaded" else {
|
guard cachedStatus.contains(cloudDownloadResponse.status) else {
|
||||||
throw DebridError.IsCaching
|
throw DebridError.IsCaching
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ class RealDebrid: PollingDebridSource, ObservableObject {
|
||||||
let id = "RealDebrid"
|
let id = "RealDebrid"
|
||||||
let abbreviation = "RD"
|
let abbreviation = "RD"
|
||||||
let website = "https://real-debrid.com"
|
let website = "https://real-debrid.com"
|
||||||
|
let cachedStatus: [String] = ["downloaded"]
|
||||||
var authTask: Task<Void, Error>?
|
var authTask: Task<Void, Error>?
|
||||||
|
|
||||||
@Published var authProcessing: Bool = false
|
@Published var authProcessing: Bool = false
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ class TorBox: DebridSource, ObservableObject {
|
||||||
let website = "https://torbox.app"
|
let website = "https://torbox.app"
|
||||||
let description: String? = "TorBox is a debrid service that is used for downloads and media playback with seeding. " +
|
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."
|
"Both free and paid plans are available."
|
||||||
|
let cachedStatus: [String] = ["cached", "completed"]
|
||||||
|
|
||||||
@Published var authProcessing: Bool = false
|
@Published var authProcessing: Bool = false
|
||||||
var isLoggedIn: Bool {
|
var isLoggedIn: Bool {
|
||||||
|
|
@ -155,7 +156,7 @@ class TorBox: DebridSource, ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user magnet isn't saved, it's considered as caching
|
// 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
|
throw DebridError.IsCaching
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -245,7 +246,7 @@ class TorBox: DebridSource, ObservableObject {
|
||||||
DebridCloudMagnet(
|
DebridCloudMagnet(
|
||||||
id: String(cloudMagnet.id),
|
id: String(cloudMagnet.id),
|
||||||
fileName: cloudMagnet.name,
|
fileName: cloudMagnet.name,
|
||||||
status: cloudMagnet.downloadState == "cached" || cloudMagnet.downloadState == "completed" ? "downloaded" : cloudMagnet.downloadState,
|
status: cloudMagnet.downloadState,
|
||||||
hash: cloudMagnet.hash,
|
hash: cloudMagnet.hash,
|
||||||
links: cloudMagnet.files.map { String($0.id) }
|
links: cloudMagnet.files.map { String($0.id) }
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ protocol DebridSource: AnyObservableObject {
|
||||||
var abbreviation: String { get }
|
var abbreviation: String { get }
|
||||||
var website: String { get }
|
var website: String { get }
|
||||||
var description: String? { get }
|
var description: String? { get }
|
||||||
|
var cachedStatus: [String] { get }
|
||||||
|
|
||||||
// Auth variables
|
// Auth variables
|
||||||
var authProcessing: Bool { get set }
|
var authProcessing: Bool { get set }
|
||||||
|
|
@ -59,6 +60,10 @@ extension DebridSource {
|
||||||
var description: String? {
|
var description: String? {
|
||||||
nil
|
nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cachedStatus: [String] {
|
||||||
|
[]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol PollingDebridSource: DebridSource {
|
protocol PollingDebridSource: DebridSource {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ struct CloudMagnetView: View {
|
||||||
searchText.isEmpty ? true : $0.fileName.lowercased().contains(searchText.lowercased())
|
searchText.isEmpty ? true : $0.fileName.lowercased().contains(searchText.lowercased())
|
||||||
}, id: \.self) { cloudMagnet in
|
}, id: \.self) { cloudMagnet in
|
||||||
Button {
|
Button {
|
||||||
if cloudMagnet.status == "downloaded", !cloudMagnet.links.isEmpty {
|
if debridSource.cachedStatus.contains(cloudMagnet.status), !cloudMagnet.links.isEmpty {
|
||||||
navModel.resultFromCloud = true
|
navModel.resultFromCloud = true
|
||||||
navModel.selectedTitle = cloudMagnet.fileName
|
navModel.selectedTitle = cloudMagnet.fileName
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,8 @@ struct DebridCloudView: View {
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
if !debridSource.cloudDownloads.isEmpty {
|
CloudDownloadView(debridSource: debridSource, searchText: $searchText)
|
||||||
CloudDownloadView(debridSource: debridSource, searchText: $searchText)
|
CloudMagnetView(debridSource: debridSource, searchText: $searchText)
|
||||||
}
|
|
||||||
|
|
||||||
if !debridSource.cloudMagnets.isEmpty {
|
|
||||||
CloudMagnetView(debridSource: debridSource, searchText: $searchText)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.listStyle(.plain)
|
.listStyle(.plain)
|
||||||
.task {
|
.task {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue