Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit d0e8400

Browse files
authored
Refactor certificate handling and UI components
1 parent b5409d3 commit d0e8400

File tree

1 file changed

+14
-38
lines changed

1 file changed

+14
-38
lines changed

Sources/prostore/certificates/OfficialCertsDownloader.swift

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct TreeResponse: Codable {
3232
let truncated: Bool?
3333
}
3434

35-
struct TreeItem: Codable, Identifiable {
35+
struct TreeItem: Codable, Identifiable, Hashable, Equatable {
3636
let path: String
3737
let type: String
3838
let url: String
@@ -47,37 +47,6 @@ struct BlobResponse: Codable {
4747
let content: String?
4848
}
4949

50-
// MARK: - Date Extension for Formatting
51-
extension Date {
52-
func formattedWithOrdinal() -> String {
53-
let formatter = DateFormatter()
54-
formatter.dateFormat = "MMMM"
55-
let month = formatter.string(from: self)
56-
let day = Calendar.current.component(.day, from: self)
57-
let ordinal = ordinalSuffix(for: day)
58-
let year = Calendar.current.component(.year, from: self)
59-
return "\(ordinal) of \(month) \(year)"
60-
}
61-
62-
private func ordinalSuffix(for number: Int) -> String {
63-
let suffix: String
64-
let ones = number % 10
65-
let tens = (number / 10) % 10
66-
if tens == 1 {
67-
suffix = "th"
68-
} else if ones == 1 {
69-
suffix = "st"
70-
} else if ones == 2 {
71-
suffix = "nd"
72-
} else if ones == 3 {
73-
suffix = "rd"
74-
} else {
75-
suffix = "th"
76-
}
77-
return "\(number)\(suffix)"
78-
}
79-
}
80-
8150
// MARK: - Loyahdev Certificates View
8251
struct LoyahdevCertificatesView: View {
8352
@Environment(\.dismiss) private var dismiss
@@ -526,8 +495,10 @@ struct OfficialCertificatesView: View {
526495
statusMessage = "Fetching..."
527496
Task {
528497
do {
529-
let subUrl = item.url
530-
let (subData, _) = try await URLSession.shared.data(from: subUrl)
498+
guard let subURL = URL(string: item.url) else {
499+
throw NSError(domain: "URL", code: 1, userInfo: [NSLocalizedDescriptionKey: "Invalid subdirectory URL"])
500+
}
501+
let (subData, _) = try await URLSession.shared.data(from: subURL)
531502
let decoder = JSONDecoder()
532503
let subResponse = try decoder.decode(TreeResponse.self, from: subData)
533504
let subTree = subResponse.tree
@@ -537,9 +508,14 @@ struct OfficialCertificatesView: View {
537508
guard let p12Blob = p12Item, let provBlob = provItem, let pwBlobItem = pwItem else {
538509
throw NSError(domain: "Files", code: 1, userInfo: [NSLocalizedDescriptionKey: "Missing required files"])
539510
}
540-
let p12DataLocal = try await fetchBlobContent(url: p12Blob.url)
541-
let provDataLocal = try await fetchBlobContent(url: provBlob.url)
542-
let pwData = try await fetchBlobContent(url: pwBlobItem.url)
511+
guard let p12URL = URL(string: p12Blob.url),
512+
let provURL = URL(string: provBlob.url),
513+
let pwURL = URL(string: pwBlobItem.url) else {
514+
throw NSError(domain: "URL", code: 1, userInfo: [NSLocalizedDescriptionKey: "Invalid blob URLs"])
515+
}
516+
let p12DataLocal = try await fetchBlobContent(url: p12URL)
517+
let provDataLocal = try await fetchBlobContent(url: provURL)
518+
let pwData = try await fetchBlobContent(url: pwURL)
543519
guard let pwString = String(data: pwData, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) else {
544520
throw NSError(domain: "Password", code: 1, userInfo: [NSLocalizedDescriptionKey: "Invalid password file"])
545521
}
@@ -596,4 +572,4 @@ struct OfficialCertificatesView: View {
596572
}
597573
}
598574
}
599-
}
575+
}

0 commit comments

Comments
 (0)