Ferrite: format
Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
e8f62e3cdc
commit
39c4a10a72
11 changed files with 27 additions and 24 deletions
|
|
@ -11,11 +11,11 @@ import Foundation
|
||||||
extension String {
|
extension String {
|
||||||
// From https://www.hackingwithswift.com/example-code/strings/how-to-capitalize-the-first-letter-of-a-string
|
// From https://www.hackingwithswift.com/example-code/strings/how-to-capitalize-the-first-letter-of-a-string
|
||||||
func capitalizingFirstLetter() -> String {
|
func capitalizingFirstLetter() -> String {
|
||||||
return prefix(1).capitalized + dropFirst()
|
prefix(1).capitalized + dropFirst()
|
||||||
}
|
}
|
||||||
|
|
||||||
mutating func capitalizeFirstLetter() {
|
mutating func capitalizeFirstLetter() {
|
||||||
self = self.capitalizingFirstLetter()
|
self = capitalizingFirstLetter()
|
||||||
}
|
}
|
||||||
|
|
||||||
// From https://stackoverflow.com/a/59307884
|
// From https://stackoverflow.com/a/59307884
|
||||||
|
|
|
||||||
|
|
@ -89,11 +89,11 @@ public extension AllDebrid {
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
|
||||||
if let data = try? container.decode(MagnetStatusData.self, forKey: .magnets) {
|
if let data = try? container.decode(MagnetStatusData.self, forKey: .magnets) {
|
||||||
self.magnets = [data]
|
magnets = [data]
|
||||||
} else if let data = try? container.decode([MagnetStatusData].self, forKey: .magnets) {
|
} else if let data = try? container.decode([MagnetStatusData].self, forKey: .magnets) {
|
||||||
self.magnets = data
|
magnets = data
|
||||||
} else {
|
} else {
|
||||||
self.magnets = []
|
magnets = []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
// Created by Brian Dashore on 11/27/22.
|
// Created by Brian Dashore on 11/27/22.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import Base32
|
import Base32
|
||||||
|
import Foundation
|
||||||
|
|
||||||
// MARK: - Universal IA enum (IA = InstantAvailability)
|
// MARK: - Universal IA enum (IA = InstantAvailability)
|
||||||
|
|
||||||
|
|
@ -41,10 +41,10 @@ public struct Magnet: Codable, Hashable, Sendable {
|
||||||
var link: String?
|
var link: String?
|
||||||
|
|
||||||
init(hash: String?, link: String?, title: String? = nil, trackers: [String]? = nil) {
|
init(hash: String?, link: String?, title: String? = nil, trackers: [String]? = nil) {
|
||||||
if let hash = hash, link == nil {
|
if let hash, link == nil {
|
||||||
self.hash = parseHash(hash)
|
self.hash = parseHash(hash)
|
||||||
self.link = generateLink(hash: hash, title: title, trackers: trackers)
|
self.link = generateLink(hash: hash, title: title, trackers: trackers)
|
||||||
} else if let link = link, hash == nil {
|
} else if let link, hash == nil {
|
||||||
self.link = link
|
self.link = link
|
||||||
self.hash = parseHash(extractHash(link: link))
|
self.hash = parseHash(extractHash(link: link))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -67,12 +67,14 @@ public extension Premiumize {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - AllItemsResponse (listall endpoint)
|
// MARK: - AllItemsResponse (listall endpoint)
|
||||||
|
|
||||||
struct AllItemsResponse: Codable {
|
struct AllItemsResponse: Codable {
|
||||||
let status: String
|
let status: String
|
||||||
let files: [UserItem]
|
let files: [UserItem]
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: User Items
|
// MARK: User Items
|
||||||
|
|
||||||
// Abridged for required parameters
|
// Abridged for required parameters
|
||||||
struct UserItem: Codable {
|
struct UserItem: Codable {
|
||||||
let id: String
|
let id: String
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ public class DebridManager: ObservableObject {
|
||||||
|
|
||||||
// Wrapper function to match error descriptions
|
// Wrapper function to match error descriptions
|
||||||
// Error can be suppressed to end user but must be printed in logs
|
// Error can be suppressed to end user but must be printed in logs
|
||||||
func sendDebridError(_ error: Error, prefix: String, presentError: Bool = true, cancelString: String? = nil) async {
|
func sendDebridError(_ error: Error, prefix: String, presentError: Bool = true, cancelString: String? = nil) async {
|
||||||
let error = error as NSError
|
let error = error as NSError
|
||||||
if presentError {
|
if presentError {
|
||||||
if let cancelString, error.code == -999 {
|
if let cancelString, error.code == -999 {
|
||||||
|
|
@ -589,7 +589,7 @@ public class DebridManager: ObservableObject {
|
||||||
|
|
||||||
func deleteRdTorrent(torrentID: String? = nil, presentError: Bool = true) async {
|
func deleteRdTorrent(torrentID: String? = nil, presentError: Bool = true) async {
|
||||||
do {
|
do {
|
||||||
if let torrentID = torrentID {
|
if let torrentID {
|
||||||
try await realDebrid.deleteTorrent(debridID: torrentID)
|
try await realDebrid.deleteTorrent(debridID: torrentID)
|
||||||
} else if let selectedTorrentID = selectedRealDebridID {
|
} else if let selectedTorrentID = selectedRealDebridID {
|
||||||
try await realDebrid.deleteTorrent(debridID: selectedTorrentID)
|
try await realDebrid.deleteTorrent(debridID: selectedTorrentID)
|
||||||
|
|
|
||||||
|
|
@ -31,20 +31,20 @@ struct BookmarksView: View {
|
||||||
for index in offsets {
|
for index in offsets {
|
||||||
if let bookmark = bookmarks[safe: index] {
|
if let bookmark = bookmarks[safe: index] {
|
||||||
PersistenceController.shared.delete(bookmark, context: backgroundContext)
|
PersistenceController.shared.delete(bookmark, context: backgroundContext)
|
||||||
|
|
||||||
NotificationCenter.default.post(name: .didDeleteBookmark, object: bookmark)
|
NotificationCenter.default.post(name: .didDeleteBookmark, object: bookmark)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onMove { source, destination in
|
.onMove { source, destination in
|
||||||
var changedBookmarks = bookmarks.map { $0 }
|
var changedBookmarks = bookmarks.map { $0 }
|
||||||
|
|
||||||
changedBookmarks.move(fromOffsets: source, toOffset: destination)
|
changedBookmarks.move(fromOffsets: source, toOffset: destination)
|
||||||
|
|
||||||
for reverseIndex in stride(from: changedBookmarks.count - 1, through: 0, by: -1) {
|
for reverseIndex in stride(from: changedBookmarks.count - 1, through: 0, by: -1) {
|
||||||
changedBookmarks[reverseIndex].orderNum = Int16(reverseIndex)
|
changedBookmarks[reverseIndex].orderNum = Int16(reverseIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistenceController.shared.save()
|
PersistenceController.shared.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ struct AllDebridCloudView: View {
|
||||||
searchText.isEmpty ? true : $0.filename.lowercased().contains(searchText.lowercased())
|
searchText.isEmpty ? true : $0.filename.lowercased().contains(searchText.lowercased())
|
||||||
}, id: \.id) { magnet in
|
}, id: \.id) { magnet in
|
||||||
Button {
|
Button {
|
||||||
if magnet.status == "Ready" && !magnet.links.isEmpty {
|
if magnet.status == "Ready", !magnet.links.isEmpty {
|
||||||
navModel.resultFromCloud = true
|
navModel.resultFromCloud = true
|
||||||
navModel.selectedTitle = magnet.filename
|
navModel.selectedTitle = magnet.filename
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ struct RealDebridCloudView: View {
|
||||||
searchText.isEmpty ? true : $0.filename.lowercased().contains(searchText.lowercased())
|
searchText.isEmpty ? true : $0.filename.lowercased().contains(searchText.lowercased())
|
||||||
}, id: \.self) { torrentResponse in
|
}, id: \.self) { torrentResponse in
|
||||||
Button {
|
Button {
|
||||||
if torrentResponse.status == "downloaded" && !torrentResponse.links.isEmpty {
|
if torrentResponse.status == "downloaded", !torrentResponse.links.isEmpty {
|
||||||
navModel.resultFromCloud = true
|
navModel.resultFromCloud = true
|
||||||
navModel.selectedTitle = torrentResponse.filename
|
navModel.selectedTitle = torrentResponse.filename
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ struct HistoryView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
func groupedHistory(_ result: FetchedResults<History>) -> [[History]] {
|
func groupedHistory(_ result: FetchedResults<History>) -> [[History]] {
|
||||||
return Dictionary(grouping: result) { (element: History) in
|
Dictionary(grouping: result) { (element: History) in
|
||||||
element.dateString ?? ""
|
element.dateString ?? ""
|
||||||
}
|
}
|
||||||
.values
|
.values
|
||||||
|
|
@ -87,9 +87,9 @@ struct HistorySectionView: View {
|
||||||
func compareGroup(_ group: [History]) -> Int {
|
func compareGroup(_ group: [History]) -> Int {
|
||||||
var totalCount = 0
|
var totalCount = 0
|
||||||
for history in group {
|
for history in group {
|
||||||
totalCount += history.entryArray.reduce(0, { result, item in
|
totalCount += history.entryArray.reduce(0) { result, item in
|
||||||
result + (allEntries.contains { $0.name == item.name || (item.subName.map { return !$0.isEmpty } ?? false && $0.subName == item.subName) } ? 1 : 0)
|
result + (allEntries.contains { $0.name == item.name || (item.subName.map { !$0.isEmpty } ?? false && $0.subName == item.subName) } ? 1 : 0)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return totalCount
|
return totalCount
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ struct SearchResultButtonView: View {
|
||||||
source: result.source
|
source: result.source
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
navModel.runDebridAction(urlString: debridManager.downloadUrl)
|
navModel.runDebridAction(urlString: debridManager.downloadUrl)
|
||||||
|
|
||||||
if navModel.currentChoiceSheet != .magnet {
|
if navModel.currentChoiceSheet != .magnet {
|
||||||
|
|
@ -130,8 +130,9 @@ struct SearchResultButtonView: View {
|
||||||
.onReceive(NotificationCenter.default.publisher(for: .didDeleteBookmark)) { notification in
|
.onReceive(NotificationCenter.default.publisher(for: .didDeleteBookmark)) { notification in
|
||||||
// If the instance contains the deleted bookmark, remove it.
|
// If the instance contains the deleted bookmark, remove it.
|
||||||
if let deletedBookmark = notification.object as? Bookmark,
|
if let deletedBookmark = notification.object as? Bookmark,
|
||||||
let bookmark = existingBookmark,
|
let bookmark = existingBookmark,
|
||||||
deletedBookmark.objectID == bookmark.objectID {
|
deletedBookmark.objectID == bookmark.objectID
|
||||||
|
{
|
||||||
existingBookmark = nil
|
existingBookmark = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ struct SourceSettingsView: View {
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
PersistenceController.shared.save()
|
PersistenceController.shared.save()
|
||||||
}
|
}
|
||||||
.navigationTitle("Source settings")
|
.navigationTitle("Source Settings")
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .navigationBarTrailing) {
|
ToolbarItem(placement: .navigationBarTrailing) {
|
||||||
Button("Done") {
|
Button("Done") {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue