Ferrite-backup/Ferrite/Models/PremiumizeModels.swift
kingbri 5a4e98f10d Ferrite: Switch to a Magnet struct
Magnets are expressed in two different ways: a hash and a link. Both
of these mean the same thing with a magnet link giving more information
if required.

However, there was a disconnect if a hash was present or a link was
present and required many steps to check which was available. Unify
magnets by creating a parent structure that attempts to extract
the hash or create a link in the event that either parameter isn't
provided.

Replace everything except bookmarks (to prevent CoreData complaints
and unnecessary abstraction) to use the new Magnet system.

Signed-off-by: kingbri <bdashore3@proton.me>
2023-01-04 12:49:20 -05:00

102 lines
2.2 KiB
Swift

//
// PremiumizeModels.swift
// Ferrite
//
// Created by Brian Dashore on 11/28/22.
//
import Foundation
public extension Premiumize {
// MARK: - Errors
// TODO: Hybridize debrid errors in one structure
enum PMError: Error {
case InvalidUrl
case InvalidPostBody
case InvalidResponse
case InvalidToken
case EmptyData
case EmptyTorrents
case FailedRequest(description: String)
case AuthQuery(description: String)
}
// MARK: - CacheCheckResponse
struct CacheCheckResponse: Codable {
let status: String
let response: [Bool]
}
// MARK: - DDLResponse
struct DDLResponse: Codable {
let status: String
let content: [DDLData]
let location: String
let filename: String
let filesize: Int
}
// MARK: Content
struct DDLData: Codable {
let path: String
let size: Int
let link: String
let streamLink: String
enum CodingKeys: String, CodingKey {
case path, size, link
case streamLink = "stream_link"
}
}
// MARK: - InstantAvailability client side structures
struct IA: Codable, Hashable {
let magnet: Magnet
let expiryTimeStamp: Double
let files: [IAFile]
}
struct IAFile: Codable, Hashable {
let name: String
let streamUrlString: String
}
// MARK: - AllItemsResponse (listall endpoint)
struct AllItemsResponse: Codable {
let status: String
let files: [UserItem]
}
// MARK: User Items
// Abridged for required parameters
struct UserItem: Codable {
let id: String
let name: String
let mimeType: String
enum CodingKeys: String, CodingKey {
case id, name
case mimeType = "mime_type"
}
}
// MARK: - ItemDetailsResponse
// Abridged for required parameters
struct ItemDetailsResponse: Codable {
let id: String
let name: String
let link: String
let mimeType: String
enum CodingKeys: String, CodingKey {
case id, name, link
case mimeType = "mime_type"
}
}
}