Ferrite-backup/Ferrite/Models/BackupModels.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

52 lines
1.1 KiB
Swift

//
// BackupModels.swift
// Ferrite
//
// Created by Brian Dashore on 9/17/22.
//
import Foundation
public struct Backup: Codable {
let version: Int
var bookmarks: [BookmarkJson]?
var history: [HistoryJson]?
var sourceNames: [String]?
var sourceLists: [SourceListBackupJson]?
}
// MARK: - CoreData translation
// Don't typealias to search result as this is a reflection of CoreData's struct
struct BookmarkJson: Codable {
let title: String?
let source: String
let size: String?
let magnetLink: String?
let magnetHash: String?
let seeders: String?
let leechers: String?
}
// Date is an epoch timestamp
struct HistoryJson: Codable {
let dateString: String?
let date: Double
let entries: [HistoryEntryJson]
}
struct HistoryEntryJson: Codable {
var name: String? = nil
var subName: String? = nil
var url: String? = nil
var timeStamp: Double? = nil
let source: String?
}
// Differs from SourceListJson
struct SourceListBackupJson: Codable {
let name: String
let author: String
let id: String
let urlString: String
}