Ferrite: format

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri 2023-01-07 17:40:44 -05:00
parent e8f62e3cdc
commit 39c4a10a72
11 changed files with 27 additions and 24 deletions

View file

@ -11,11 +11,11 @@ import Foundation
extension String {
// From https://www.hackingwithswift.com/example-code/strings/how-to-capitalize-the-first-letter-of-a-string
func capitalizingFirstLetter() -> String {
return prefix(1).capitalized + dropFirst()
prefix(1).capitalized + dropFirst()
}
mutating func capitalizeFirstLetter() {
self = self.capitalizingFirstLetter()
self = capitalizingFirstLetter()
}
// From https://stackoverflow.com/a/59307884

View file

@ -89,11 +89,11 @@ public extension AllDebrid {
let container = try decoder.container(keyedBy: CodingKeys.self)
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) {
self.magnets = data
magnets = data
} else {
self.magnets = []
magnets = []
}
}
}

View file

@ -5,8 +5,8 @@
// Created by Brian Dashore on 11/27/22.
//
import Foundation
import Base32
import Foundation
// MARK: - Universal IA enum (IA = InstantAvailability)
@ -41,10 +41,10 @@ public struct Magnet: Codable, Hashable, Sendable {
var link: String?
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.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.hash = parseHash(extractHash(link: link))
} else {

View file

@ -67,12 +67,14 @@ public extension Premiumize {
}
// 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

View file

@ -122,7 +122,7 @@ public class DebridManager: ObservableObject {
// Wrapper function to match error descriptions
// 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
if presentError {
if let cancelString, error.code == -999 {
@ -589,7 +589,7 @@ public class DebridManager: ObservableObject {
func deleteRdTorrent(torrentID: String? = nil, presentError: Bool = true) async {
do {
if let torrentID = torrentID {
if let torrentID {
try await realDebrid.deleteTorrent(debridID: torrentID)
} else if let selectedTorrentID = selectedRealDebridID {
try await realDebrid.deleteTorrent(debridID: selectedTorrentID)

View file

@ -31,20 +31,20 @@ struct BookmarksView: View {
for index in offsets {
if let bookmark = bookmarks[safe: index] {
PersistenceController.shared.delete(bookmark, context: backgroundContext)
NotificationCenter.default.post(name: .didDeleteBookmark, object: bookmark)
}
}
}
.onMove { source, destination in
var changedBookmarks = bookmarks.map { $0 }
changedBookmarks.move(fromOffsets: source, toOffset: destination)
for reverseIndex in stride(from: changedBookmarks.count - 1, through: 0, by: -1) {
changedBookmarks[reverseIndex].orderNum = Int16(reverseIndex)
}
PersistenceController.shared.save()
}
}

View file

@ -21,7 +21,7 @@ struct AllDebridCloudView: View {
searchText.isEmpty ? true : $0.filename.lowercased().contains(searchText.lowercased())
}, id: \.id) { magnet in
Button {
if magnet.status == "Ready" && !magnet.links.isEmpty {
if magnet.status == "Ready", !magnet.links.isEmpty {
navModel.resultFromCloud = true
navModel.selectedTitle = magnet.filename

View file

@ -54,7 +54,7 @@ struct RealDebridCloudView: View {
searchText.isEmpty ? true : $0.filename.lowercased().contains(searchText.lowercased())
}, id: \.self) { torrentResponse in
Button {
if torrentResponse.status == "downloaded" && !torrentResponse.links.isEmpty {
if torrentResponse.status == "downloaded", !torrentResponse.links.isEmpty {
navModel.resultFromCloud = true
navModel.selectedTitle = torrentResponse.filename

View file

@ -46,7 +46,7 @@ struct HistoryView: View {
}
func groupedHistory(_ result: FetchedResults<History>) -> [[History]] {
return Dictionary(grouping: result) { (element: History) in
Dictionary(grouping: result) { (element: History) in
element.dateString ?? ""
}
.values
@ -87,9 +87,9 @@ struct HistorySectionView: View {
func compareGroup(_ group: [History]) -> Int {
var totalCount = 0
for history in group {
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)
})
totalCount += history.entryArray.reduce(0) { result, item in
result + (allEntries.contains { $0.name == item.name || (item.subName.map { !$0.isEmpty } ?? false && $0.subName == item.subName) } ? 1 : 0)
}
}
return totalCount

View file

@ -40,7 +40,7 @@ struct SearchResultButtonView: View {
source: result.source
)
)
navModel.runDebridAction(urlString: debridManager.downloadUrl)
if navModel.currentChoiceSheet != .magnet {
@ -130,8 +130,9 @@ struct SearchResultButtonView: View {
.onReceive(NotificationCenter.default.publisher(for: .didDeleteBookmark)) { notification in
// If the instance contains the deleted bookmark, remove it.
if let deletedBookmark = notification.object as? Bookmark,
let bookmark = existingBookmark,
deletedBookmark.objectID == bookmark.objectID {
let bookmark = existingBookmark,
deletedBookmark.objectID == bookmark.objectID
{
existingBookmark = nil
}
}

View file

@ -60,7 +60,7 @@ struct SourceSettingsView: View {
.onDisappear {
PersistenceController.shared.save()
}
.navigationTitle("Source settings")
.navigationTitle("Source Settings")
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button("Done") {