Debrid: Remove ID storage
Storing an ID reference is redundant. Store a class reference instead. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
07731e7b00
commit
9650e6deec
14 changed files with 45 additions and 50 deletions
|
|
@ -9,9 +9,9 @@ import Foundation
|
|||
|
||||
// TODO: Fix errors
|
||||
public class AllDebrid: PollingDebridSource, ObservableObject {
|
||||
public let id = DebridInfo(
|
||||
name: "AllDebrid", abbreviation: "AD", website: "https://alldebrid.com"
|
||||
)
|
||||
public let id = "AllDebrid"
|
||||
public let abbreviation = "AD"
|
||||
public let website = "https://alldebrid.com"
|
||||
public var authTask: Task<Void, Error>?
|
||||
|
||||
public var authProcessing: Bool = false
|
||||
|
|
@ -178,7 +178,7 @@ public class AllDebrid: PollingDebridSource, ObservableObject {
|
|||
|
||||
return DebridIA(
|
||||
magnet: Magnet(hash: magnetResp.hash, link: magnetResp.magnet),
|
||||
source: self.id.name,
|
||||
source: self.id,
|
||||
expiryTimeStamp: Date().timeIntervalSince1970 + 300,
|
||||
files: files
|
||||
)
|
||||
|
|
@ -292,7 +292,7 @@ public class AllDebrid: PollingDebridSource, ObservableObject {
|
|||
cloudTorrents = rawResponse.magnets.map { magnetResponse in
|
||||
DebridCloudTorrent(
|
||||
torrentId: String(magnetResponse.id),
|
||||
source: self.id.name,
|
||||
source: self.id,
|
||||
fileName: magnetResponse.filename,
|
||||
status: magnetResponse.status,
|
||||
hash: magnetResponse.hash,
|
||||
|
|
@ -325,7 +325,7 @@ public class AllDebrid: PollingDebridSource, ObservableObject {
|
|||
// The link is also the ID
|
||||
cloudDownloads = rawResponse.links.map { link in
|
||||
DebridCloudDownload(
|
||||
downloadId: link.link, source: self.id.name, fileName: link.filename, link: link.link
|
||||
downloadId: link.link, source: self.id, fileName: link.filename, link: link.link
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,9 @@
|
|||
import Foundation
|
||||
|
||||
public class Premiumize: OAuthDebridSource, ObservableObject {
|
||||
public let id = DebridInfo(
|
||||
name: "Premiumize", abbreviation: "PM", website: "https://premiumize.me"
|
||||
)
|
||||
|
||||
public let id = "Premiumize"
|
||||
public let abbreviation = "PM"
|
||||
public let website = "https://premiumize.me"
|
||||
@Published public var authProcessing: Bool = false
|
||||
public var isLoggedIn: Bool {
|
||||
getToken() != nil
|
||||
|
|
@ -195,7 +194,7 @@ public class Premiumize: OAuthDebridSource, ObservableObject {
|
|||
|
||||
return DebridIA(
|
||||
magnet: magnet,
|
||||
source: id.name,
|
||||
source: id,
|
||||
expiryTimeStamp: Date().timeIntervalSince1970 + 300,
|
||||
files: files
|
||||
)
|
||||
|
|
@ -300,7 +299,7 @@ public class Premiumize: OAuthDebridSource, ObservableObject {
|
|||
|
||||
// The "link" is the ID for Premiumize
|
||||
cloudDownloads = rawResponse.files.map { file in
|
||||
DebridCloudDownload(downloadId: file.id, source: self.id.name, fileName: file.name, link: file.id)
|
||||
DebridCloudDownload(downloadId: file.id, source: self.id, fileName: file.name, link: file.id)
|
||||
}
|
||||
|
||||
return cloudDownloads
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@
|
|||
import Foundation
|
||||
|
||||
public class RealDebrid: PollingDebridSource, ObservableObject {
|
||||
public let id = DebridInfo(
|
||||
name: "RealDebrid", abbreviation: "RD", website: "https://real-debrid.com"
|
||||
)
|
||||
public let id = "RealDebrid"
|
||||
public let abbreviation = "RD"
|
||||
public let website = "https://real-debrid.com"
|
||||
public var authTask: Task<Void, Error>?
|
||||
|
||||
@Published public var authProcessing: Bool = false
|
||||
|
|
@ -287,7 +287,7 @@ public class RealDebrid: PollingDebridSource, ObservableObject {
|
|||
IAValues.append(
|
||||
DebridIA(
|
||||
magnet: Magnet(hash: hash, link: nil),
|
||||
source: id.name,
|
||||
source: id,
|
||||
expiryTimeStamp: Date().timeIntervalSince1970 + 300,
|
||||
files: files
|
||||
)
|
||||
|
|
@ -296,7 +296,7 @@ public class RealDebrid: PollingDebridSource, ObservableObject {
|
|||
IAValues.append(
|
||||
DebridIA(
|
||||
magnet: Magnet(hash: hash, link: nil),
|
||||
source: id.name,
|
||||
source: id,
|
||||
expiryTimeStamp: Date().timeIntervalSince1970 + 300,
|
||||
files: []
|
||||
)
|
||||
|
|
@ -427,7 +427,7 @@ public class RealDebrid: PollingDebridSource, ObservableObject {
|
|||
cloudTorrents = rawResponse.map { response in
|
||||
DebridCloudTorrent(
|
||||
torrentId: response.id,
|
||||
source: self.id.name,
|
||||
source: self.id,
|
||||
fileName: response.filename,
|
||||
status: response.status,
|
||||
hash: response.hash,
|
||||
|
|
@ -453,7 +453,7 @@ public class RealDebrid: PollingDebridSource, ObservableObject {
|
|||
let data = try await performRequest(request: &request, requestName: #function)
|
||||
let rawResponse = try jsonDecoder.decode([UserDownloadsResponse].self, from: data)
|
||||
cloudDownloads = rawResponse.map { response in
|
||||
DebridCloudDownload(downloadId: response.id, source: self.id.name, fileName: response.filename, link: response.download)
|
||||
DebridCloudDownload(downloadId: response.id, source: self.id, fileName: response.filename, link: response.download)
|
||||
}
|
||||
|
||||
return cloudDownloads
|
||||
|
|
|
|||
|
|
@ -7,12 +7,6 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
public struct DebridInfo: Hashable, Sendable {
|
||||
let name: String
|
||||
let abbreviation: String
|
||||
let website: String
|
||||
}
|
||||
|
||||
public struct DebridIA: Hashable, Sendable {
|
||||
let magnet: Magnet
|
||||
let source: String
|
||||
|
|
|
|||
|
|
@ -9,7 +9,10 @@ import Foundation
|
|||
|
||||
public protocol DebridSource: AnyObservableObject {
|
||||
// ID of the service
|
||||
var id: DebridInfo { get }
|
||||
//var id: DebridInfo { get }
|
||||
var id: String { get }
|
||||
var abbreviation: String { get }
|
||||
var website: String { get }
|
||||
|
||||
// Auth variables
|
||||
var authProcessing: Bool { get set }
|
||||
|
|
|
|||
|
|
@ -26,11 +26,13 @@ public class DebridManager: ObservableObject {
|
|||
debridSources.contains { $0.isLoggedIn }
|
||||
}
|
||||
|
||||
@Published var selectedDebridId: DebridInfo?
|
||||
@Published var selectedDebridSource: DebridSource?
|
||||
|
||||
/*
|
||||
func debridSourceFromName(_ name: String? = nil) -> DebridSource? {
|
||||
debridSources.first { $0.id.name == name ?? selectedDebridId?.name }
|
||||
}
|
||||
*/
|
||||
|
||||
// Service agnostic variables
|
||||
@Published var enabledDebrids: Set<DebridType> = [] {
|
||||
|
|
@ -113,8 +115,7 @@ public class DebridManager: ObservableObject {
|
|||
// If a UserDefaults integer isn't set, it's usually 0
|
||||
let rawPreferredService = UserDefaults.standard.integer(forKey: "Debrid.PreferredService")
|
||||
let legacyPreferredService = DebridType(rawValue: rawPreferredService)
|
||||
let preferredDebridSource = self.debridSourceFromName(legacyPreferredService?.toString())
|
||||
selectedDebridId = preferredDebridSource?.id
|
||||
selectedDebridSource = self.debridSources.first { $0.id == legacyPreferredService?.toString() }
|
||||
|
||||
// If a user has one logged in service, automatically set the preferred service to that one
|
||||
/*
|
||||
|
|
@ -265,10 +266,8 @@ public class DebridManager: ObservableObject {
|
|||
return .none
|
||||
}
|
||||
|
||||
let selectedSource = debridSourceFromName()
|
||||
|
||||
if let selectedSource,
|
||||
let match = selectedSource.IAValues.first(where: { magnetHash == $0.magnet.hash })
|
||||
if let selectedDebridSource,
|
||||
let match = selectedDebridSource.IAValues.first(where: { magnetHash == $0.magnet.hash })
|
||||
{
|
||||
return match.files.count > 1 ? .partial : .full
|
||||
} else {
|
||||
|
|
@ -282,7 +281,7 @@ public class DebridManager: ObservableObject {
|
|||
return false
|
||||
}
|
||||
|
||||
switch selectedDebridId?.name {
|
||||
switch selectedDebridSource?.id {
|
||||
case .some("RealDebrid"):
|
||||
if let realDebridItem = realDebrid.IAValues.first(where: { magnetHash == $0.magnet.hash }) {
|
||||
selectedRealDebridItem = realDebridItem
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ struct DebridLabelView: View {
|
|||
|
||||
var body: some View {
|
||||
Tag(
|
||||
name: debridSource.id.abbreviation,
|
||||
name: debridSource.abbreviation,
|
||||
color: tagColor,
|
||||
horizontalPadding: 5,
|
||||
verticalPadding: 3
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ struct SelectedDebridFilterView<Content: View>: View {
|
|||
var body: some View {
|
||||
Menu {
|
||||
Button {
|
||||
debridManager.selectedDebridId = nil
|
||||
debridManager.selectedDebridSource = nil
|
||||
} label: {
|
||||
Text("None")
|
||||
|
||||
if debridManager.selectedDebridId == nil {
|
||||
if debridManager.selectedDebridSource == nil {
|
||||
Image(systemName: "checkmark")
|
||||
}
|
||||
}
|
||||
|
|
@ -27,11 +27,11 @@ struct SelectedDebridFilterView<Content: View>: View {
|
|||
ForEach(debridManager.debridSources, id: \.id) { debridSource in
|
||||
if debridSource.isLoggedIn {
|
||||
Button {
|
||||
debridManager.selectedDebridId = debridSource.id
|
||||
debridManager.selectedDebridSource = debridSource
|
||||
} label: {
|
||||
Text(debridSource.id.name)
|
||||
Text(debridSource.id)
|
||||
|
||||
if debridManager.selectedDebridId == debridSource.id {
|
||||
if debridManager.selectedDebridSource?.id == debridSource.id {
|
||||
Image(systemName: "checkmark")
|
||||
}
|
||||
}
|
||||
|
|
@ -40,6 +40,6 @@ struct SelectedDebridFilterView<Content: View>: View {
|
|||
} label: {
|
||||
label
|
||||
}
|
||||
.id(debridManager.selectedDebridId)
|
||||
.id(debridManager.selectedDebridSource?.id)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ struct SearchFilterHeaderView: View {
|
|||
|
||||
SelectedDebridFilterView {
|
||||
FilterLabelView(
|
||||
name: debridManager.selectedDebridId?.name,
|
||||
name: debridManager.selectedDebridSource?.id,
|
||||
fallbackName: "Debrid"
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ struct SearchResultInfoView: View {
|
|||
Text(size)
|
||||
}
|
||||
|
||||
if let debridSource = debridManager.debridSourceFromName() {
|
||||
if let debridSource = debridManager.selectedDebridSource {
|
||||
DebridLabelView(debridSource: debridSource, magnet: result.magnet)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ struct SettingsDebridInfoView: View {
|
|||
List {
|
||||
Section(header: InlineHeader("Description")) {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text("\(debridSource.id.name) is a debrid service that is used for unrestricting downloads and media playback. You must pay to access the service.")
|
||||
Text("\(debridSource.id) is a debrid service that is used for unrestricting downloads and media playback. You must pay to access the service.")
|
||||
|
||||
Link("Website", destination: URL(string: debridSource.id.website) ?? URL(string: "https://kingbri.dev/ferrite")!)
|
||||
Link("Website", destination: URL(string: debridSource.website) ?? URL(string: "https://kingbri.dev/ferrite")!)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ struct SettingsDebridInfoView: View {
|
|||
}
|
||||
}
|
||||
.listStyle(.insetGrouped)
|
||||
.navigationTitle(debridSource.id.name)
|
||||
.navigationTitle(debridSource.id)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ struct LibraryView: View {
|
|||
EmptyInstructionView(title: "No History", message: "Start watching to build history")
|
||||
}
|
||||
case .debridCloud:
|
||||
if debridManager.selectedDebridId == nil {
|
||||
if debridManager.selectedDebridSource == nil {
|
||||
EmptyInstructionView(title: "Cloud Unavailable", message: "Listing is not available for this service")
|
||||
}
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ struct LibraryView: View {
|
|||
switch navModel.libraryPickerSelection {
|
||||
case .bookmarks, .debridCloud:
|
||||
SelectedDebridFilterView {
|
||||
Text(debridManager.selectedDebridId?.abbreviation ?? "Debrid")
|
||||
Text(debridManager.selectedDebridSource?.abbreviation ?? "Debrid")
|
||||
}
|
||||
.transaction {
|
||||
$0.animation = .none
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ struct SettingsView: View {
|
|||
SettingsDebridInfoView(debridSource: debridSource)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(debridSource.id.name)
|
||||
Text(debridSource.id)
|
||||
Spacer()
|
||||
Text(debridSource.isLoggedIn ? "Enabled" : "Disabled")
|
||||
.foregroundColor(.secondary)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ struct BatchChoiceView: View {
|
|||
var body: some View {
|
||||
NavView {
|
||||
List {
|
||||
switch debridManager.selectedDebridId?.name {
|
||||
switch debridManager.selectedDebridSource?.id {
|
||||
case .some("RealDebrid"):
|
||||
ForEach(debridManager.selectedRealDebridItem?.files ?? [], id: \.self) { file in
|
||||
if file.name.lowercased().contains(searchText.lowercased()) || searchText.isEmpty {
|
||||
|
|
|
|||
Loading…
Reference in a new issue