mirror of
https://github.com/Ferrite-iOS/Ferrite.git
synced 2026-01-11 20:10:27 +00:00
Debrid: Clarify struct properties
Doesn't make sense to use more descriptive IDs when the struct describes what the model is already. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
078e48d316
commit
489da8e82e
7 changed files with 34 additions and 47 deletions
|
|
@ -197,12 +197,11 @@ class AllDebrid: PollingDebridSource, ObservableObject {
|
|||
let availableHashes = filteredMagnets.map { magnetResp in
|
||||
// Force unwrap is OK here since the filter caught any nil values
|
||||
let files = magnetResp.files!.enumerated().map { index, magnetFile in
|
||||
DebridIAFile(fileId: index, name: magnetFile.name)
|
||||
DebridIAFile(id: index, name: magnetFile.name)
|
||||
}
|
||||
|
||||
return DebridIA(
|
||||
magnet: Magnet(hash: magnetResp.hash, link: magnetResp.magnet),
|
||||
source: self.id,
|
||||
expiryTimeStamp: Date().timeIntervalSince1970 + 300,
|
||||
files: files
|
||||
)
|
||||
|
|
@ -218,7 +217,7 @@ class AllDebrid: PollingDebridSource, ObservableObject {
|
|||
let selectedMagnetId: String
|
||||
|
||||
if let existingMagnet = cloudMagnets.first(where: { $0.hash == magnet.hash && $0.status == "Ready" }) {
|
||||
selectedMagnetId = existingMagnet.cloudMagnetId
|
||||
selectedMagnetId = existingMagnet.id
|
||||
} else {
|
||||
let magnetId = try await addMagnet(magnet: magnet)
|
||||
selectedMagnetId = String(magnetId)
|
||||
|
|
@ -226,7 +225,7 @@ class AllDebrid: PollingDebridSource, ObservableObject {
|
|||
|
||||
let lockedLink = try await fetchMagnetStatus(
|
||||
magnetId: selectedMagnetId,
|
||||
selectedIndex: iaFile?.fileId ?? 0
|
||||
selectedIndex: iaFile?.id ?? 0
|
||||
)
|
||||
|
||||
return (lockedLink, nil)
|
||||
|
|
@ -270,7 +269,7 @@ class AllDebrid: PollingDebridSource, ObservableObject {
|
|||
|
||||
// Better to fetch no link at all than the wrong link
|
||||
if let cloudMagnetFile = rawResponse.magnets[safe: 0]?.links[safe: selectedIndex ?? -1] {
|
||||
return DebridIAFile(fileId: 0, name: cloudMagnetFile.filename, streamUrlString: cloudMagnetFile.link)
|
||||
return DebridIAFile(id: 0, name: cloudMagnetFile.filename, streamUrlString: cloudMagnetFile.link)
|
||||
} else {
|
||||
throw DebridError.EmptyUserMagnets
|
||||
}
|
||||
|
|
@ -308,8 +307,7 @@ class AllDebrid: PollingDebridSource, ObservableObject {
|
|||
|
||||
cloudMagnets = rawResponse.magnets.map { magnetResponse in
|
||||
DebridCloudMagnet(
|
||||
cloudMagnetId: String(magnetResponse.id),
|
||||
source: self.id,
|
||||
id: String(magnetResponse.id),
|
||||
fileName: magnetResponse.filename,
|
||||
status: magnetResponse.status == "Ready" ? "downloaded" : magnetResponse.status,
|
||||
hash: magnetResponse.hash,
|
||||
|
|
@ -340,7 +338,7 @@ class AllDebrid: PollingDebridSource, ObservableObject {
|
|||
// The link is also the ID
|
||||
cloudDownloads = rawResponse.links.map { link in
|
||||
DebridCloudDownload(
|
||||
downloadId: link.link, source: self.id, fileName: link.filename, link: link.link
|
||||
id: link.link, fileName: link.filename, link: link.link
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,6 @@ class OffCloud: DebridSource, ObservableObject {
|
|||
let availableHashes = rawResponse.cachedItems.map {
|
||||
DebridIA(
|
||||
magnet: Magnet(hash: $0, link: nil),
|
||||
source: self.id,
|
||||
expiryTimeStamp: Date().timeIntervalSince1970 + 300,
|
||||
files: []
|
||||
)
|
||||
|
|
@ -147,8 +146,7 @@ class OffCloud: DebridSource, ObservableObject {
|
|||
}
|
||||
|
||||
selectedMagnet = DebridCloudMagnet(
|
||||
cloudMagnetId: cloudDownloadResponse.requestId,
|
||||
source: id,
|
||||
id: cloudDownloadResponse.requestId,
|
||||
fileName: cloudDownloadResponse.fileName,
|
||||
status: cloudDownloadResponse.status,
|
||||
hash: "",
|
||||
|
|
@ -156,7 +154,7 @@ class OffCloud: DebridSource, ObservableObject {
|
|||
)
|
||||
}
|
||||
|
||||
let cloudExploreLinks = try await cloudExplore(requestId: selectedMagnet.cloudMagnetId)
|
||||
let cloudExploreLinks = try await cloudExplore(requestId: selectedMagnet.id)
|
||||
|
||||
if cloudExploreLinks.count > 1 {
|
||||
var copiedIA = ia
|
||||
|
|
@ -167,7 +165,7 @@ class OffCloud: DebridSource, ObservableObject {
|
|||
}
|
||||
|
||||
return DebridIAFile(
|
||||
fileId: index,
|
||||
id: index,
|
||||
name: exploreURL.lastPathComponent,
|
||||
streamUrlString: exploreLink.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
|
||||
)
|
||||
|
|
@ -176,7 +174,7 @@ class OffCloud: DebridSource, ObservableObject {
|
|||
return (nil, copiedIA)
|
||||
} else if let exploreLink = cloudExploreLinks.first {
|
||||
let restrictedFile = DebridIAFile(
|
||||
fileId: 0,
|
||||
id: 0,
|
||||
name: selectedMagnet.fileName,
|
||||
streamUrlString: exploreLink
|
||||
)
|
||||
|
|
@ -243,8 +241,7 @@ class OffCloud: DebridSource, ObservableObject {
|
|||
}
|
||||
|
||||
return DebridCloudMagnet(
|
||||
cloudMagnetId: cloudHistory.requestId,
|
||||
source: self.id,
|
||||
id: cloudHistory.requestId,
|
||||
fileName: cloudHistory.fileName,
|
||||
status: cloudHistory.status,
|
||||
hash: magnetHash,
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ class Premiumize: OAuthDebridSource, ObservableObject {
|
|||
if !content.isEmpty {
|
||||
let files = content.map { file in
|
||||
DebridIAFile(
|
||||
fileId: 0,
|
||||
id: 0,
|
||||
name: file.path.split(separator: "/").last.flatMap { String($0) } ?? file.path,
|
||||
streamUrlString: file.link
|
||||
)
|
||||
|
|
@ -219,7 +219,6 @@ class Premiumize: OAuthDebridSource, ObservableObject {
|
|||
|
||||
return DebridIA(
|
||||
magnet: magnet,
|
||||
source: id,
|
||||
expiryTimeStamp: Date().timeIntervalSince1970 + 300,
|
||||
files: files
|
||||
)
|
||||
|
|
@ -331,7 +330,7 @@ class Premiumize: OAuthDebridSource, ObservableObject {
|
|||
|
||||
// The "link" is the ID for Premiumize
|
||||
cloudDownloads = rawResponse.files.map { file in
|
||||
DebridCloudDownload(downloadId: file.id, source: self.id, fileName: file.name, link: file.id)
|
||||
DebridCloudDownload(id: file.id, fileName: file.name, link: file.id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -288,10 +288,10 @@ class RealDebrid: PollingDebridSource, ObservableObject {
|
|||
let batchFileIds = batch.files.map(\.id)
|
||||
|
||||
for batchFile in batch.files {
|
||||
if !files.contains(where: { $0.fileId == batchFile.id }) {
|
||||
if !files.contains(where: { $0.id == batchFile.id }) {
|
||||
files.append(
|
||||
DebridIAFile(
|
||||
fileId: batchFile.id,
|
||||
id: batchFile.id,
|
||||
name: batchFile.fileName,
|
||||
batchIds: batchFileIds
|
||||
)
|
||||
|
|
@ -304,7 +304,6 @@ class RealDebrid: PollingDebridSource, ObservableObject {
|
|||
IAValues.append(
|
||||
DebridIA(
|
||||
magnet: Magnet(hash: hash, link: nil),
|
||||
source: id,
|
||||
expiryTimeStamp: Date().timeIntervalSince1970 + 300,
|
||||
files: files
|
||||
)
|
||||
|
|
@ -321,7 +320,7 @@ class RealDebrid: PollingDebridSource, ObservableObject {
|
|||
do {
|
||||
// Don't queue a new job if the magnet already exists in the user's library
|
||||
if let existingCloudMagnet = cloudMagnets.first(where: { $0.hash == magnet.hash && $0.status == "downloaded" }) {
|
||||
selectedMagnetId = existingCloudMagnet.cloudMagnetId
|
||||
selectedMagnetId = existingCloudMagnet.id
|
||||
} else {
|
||||
selectedMagnetId = try await addMagnet(magnet: magnet)
|
||||
|
||||
|
|
@ -331,7 +330,7 @@ class RealDebrid: PollingDebridSource, ObservableObject {
|
|||
// RealDebrid has 1 as the first ID for a file
|
||||
let restrictedFile = try await torrentInfo(
|
||||
debridID: selectedMagnetId,
|
||||
selectedFileId: iaFile?.fileId ?? 1
|
||||
selectedFileId: iaFile?.id ?? 1
|
||||
)
|
||||
|
||||
return (restrictedFile, nil)
|
||||
|
|
@ -398,7 +397,7 @@ class RealDebrid: PollingDebridSource, ObservableObject {
|
|||
// Let the user know if a magnet is downloading
|
||||
if let cloudMagnetLink = rawResponse.links[safe: linkIndex ?? -1], rawResponse.status == "downloaded" {
|
||||
return DebridIAFile(
|
||||
fileId: 0,
|
||||
id: 0,
|
||||
name: rawResponse.filename,
|
||||
streamUrlString: cloudMagnetLink
|
||||
)
|
||||
|
|
@ -436,8 +435,7 @@ class RealDebrid: PollingDebridSource, ObservableObject {
|
|||
let rawResponse = try jsonDecoder.decode([UserTorrentsResponse].self, from: data)
|
||||
cloudMagnets = rawResponse.map { response in
|
||||
DebridCloudMagnet(
|
||||
cloudMagnetId: response.id,
|
||||
source: self.id,
|
||||
id: response.id,
|
||||
fileName: response.filename,
|
||||
status: response.status,
|
||||
hash: response.hash,
|
||||
|
|
@ -460,7 +458,7 @@ class RealDebrid: PollingDebridSource, ObservableObject {
|
|||
throw DebridError.EmptyUserMagnets
|
||||
}
|
||||
|
||||
deleteId = firstCloudMagnet.cloudMagnetId
|
||||
deleteId = firstCloudMagnet.id
|
||||
}
|
||||
|
||||
var request = URLRequest(url: URL(string: "\(baseApiUrl)/torrents/delete/\(deleteId)")!)
|
||||
|
|
@ -476,7 +474,7 @@ 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, fileName: response.filename, link: response.download)
|
||||
DebridCloudDownload(id: response.id, fileName: response.filename, link: response.download)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -121,7 +121,6 @@ class TorBox: DebridSource, ObservableObject {
|
|||
let availableHashes = iaObjects.map { iaObject in
|
||||
DebridIA(
|
||||
magnet: Magnet(hash: iaObject.hash, link: nil),
|
||||
source: self.id,
|
||||
expiryTimeStamp: Date().timeIntervalSince1970 + 300,
|
||||
files: iaObject.files.enumerated().compactMap { index, iaFile in
|
||||
guard let fileName = iaFile.name.split(separator: "/").last else {
|
||||
|
|
@ -129,7 +128,7 @@ class TorBox: DebridSource, ObservableObject {
|
|||
}
|
||||
|
||||
return DebridIAFile(
|
||||
fileId: index,
|
||||
id: index,
|
||||
name: String(fileName)
|
||||
)
|
||||
}
|
||||
|
|
@ -153,11 +152,11 @@ class TorBox: DebridSource, ObservableObject {
|
|||
throw DebridError.IsCaching
|
||||
}
|
||||
|
||||
guard let cloudMagnetFile = filteredCloudMagnet.files[safe: iaFile?.fileId ?? 0] else {
|
||||
guard let cloudMagnetFile = filteredCloudMagnet.files[safe: iaFile?.id ?? 0] else {
|
||||
throw DebridError.EmptyUserMagnets
|
||||
}
|
||||
|
||||
let restrictedFile = DebridIAFile(fileId: cloudMagnetFile.id, name: cloudMagnetFile.name, streamUrlString: String(cloudMagnetId))
|
||||
let restrictedFile = DebridIAFile(id: cloudMagnetFile.id, name: cloudMagnetFile.name, streamUrlString: String(cloudMagnetId))
|
||||
return (restrictedFile, nil)
|
||||
}
|
||||
|
||||
|
|
@ -201,7 +200,7 @@ class TorBox: DebridSource, ObservableObject {
|
|||
components.queryItems = [
|
||||
URLQueryItem(name: "token", value: getToken()),
|
||||
URLQueryItem(name: "torrent_id", value: restrictedFile.streamUrlString),
|
||||
URLQueryItem(name: "file_id", value: String(restrictedFile.fileId))
|
||||
URLQueryItem(name: "file_id", value: String(restrictedFile.id))
|
||||
]
|
||||
|
||||
guard let url = components.url else {
|
||||
|
|
@ -237,8 +236,7 @@ class TorBox: DebridSource, ObservableObject {
|
|||
|
||||
// Only need one link to force a green badge
|
||||
DebridCloudMagnet(
|
||||
cloudMagnetId: String(cloudMagnet.id),
|
||||
source: self.id,
|
||||
id: String(cloudMagnet.id),
|
||||
fileName: cloudMagnet.name,
|
||||
status: cloudMagnet.downloadState == "cached" || cloudMagnet.downloadState == "completed" ? "downloaded" : cloudMagnet.downloadState,
|
||||
hash: cloudMagnet.hash,
|
||||
|
|
|
|||
|
|
@ -9,19 +9,18 @@ import Foundation
|
|||
|
||||
struct DebridIA: Hashable, Sendable {
|
||||
let magnet: Magnet
|
||||
let source: String
|
||||
let expiryTimeStamp: Double
|
||||
var files: [DebridIAFile]
|
||||
}
|
||||
|
||||
struct DebridIAFile: Hashable, Sendable {
|
||||
let fileId: Int
|
||||
let id: Int
|
||||
let name: String
|
||||
let streamUrlString: String?
|
||||
let batchIds: [Int]
|
||||
|
||||
init(fileId: Int, name: String, streamUrlString: String? = nil, batchIds: [Int] = []) {
|
||||
self.fileId = fileId
|
||||
init(id: Int, name: String, streamUrlString: String? = nil, batchIds: [Int] = []) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.streamUrlString = streamUrlString
|
||||
self.batchIds = batchIds
|
||||
|
|
@ -29,15 +28,13 @@ struct DebridIAFile: Hashable, Sendable {
|
|||
}
|
||||
|
||||
struct DebridCloudDownload: Hashable, Sendable {
|
||||
let downloadId: String
|
||||
let source: String
|
||||
let id: String
|
||||
let fileName: String
|
||||
let link: String
|
||||
}
|
||||
|
||||
struct DebridCloudMagnet: Hashable, Sendable {
|
||||
let cloudMagnetId: String
|
||||
let source: String
|
||||
let id: String
|
||||
let fileName: String
|
||||
let status: String
|
||||
let hash: String
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class DebridManager: ObservableObject {
|
|||
|
||||
init() {
|
||||
// Update the UI for debrid services that are enabled
|
||||
enabledDebrids = debridSources.filter { $0.isLoggedIn }
|
||||
enabledDebrids = debridSources.filter(\.isLoggedIn)
|
||||
|
||||
// Set the preferred service. Contains migration logic for earlier versions
|
||||
if let rawPreferredService = UserDefaults.standard.string(forKey: "Debrid.PreferredService") {
|
||||
|
|
@ -436,7 +436,7 @@ class DebridManager: ObservableObject {
|
|||
}
|
||||
|
||||
do {
|
||||
try await selectedSource.deleteUserDownload(downloadId: download.downloadId)
|
||||
try await selectedSource.deleteUserDownload(downloadId: download.id)
|
||||
|
||||
await fetchDebridCloud(bypassTTL: true)
|
||||
} catch {
|
||||
|
|
@ -462,7 +462,7 @@ class DebridManager: ObservableObject {
|
|||
}
|
||||
|
||||
do {
|
||||
try await selectedSource.deleteUserMagnet(cloudMagnetId: cloudMagnet.cloudMagnetId)
|
||||
try await selectedSource.deleteUserMagnet(cloudMagnetId: cloudMagnet.id)
|
||||
|
||||
await fetchDebridCloud(bypassTTL: true)
|
||||
} catch {
|
||||
|
|
|
|||
Loading…
Reference in a new issue