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

Commit ac90a96

Browse files
authored
Refactor certificate fetching and validation logic
Refactor OfficialCertsDownloader to improve certificate fetching logic and add validation for required files.
1 parent 231d91c commit ac90a96

1 file changed

Lines changed: 35 additions & 16 deletions

File tree

Sources/prostore/certificates/OfficialCertsDownloader.swift

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,26 +163,44 @@ struct OfficialCertificatesView: View {
163163
.font(.caption)
164164
}
165165

166-
private func fetchTrees() {
167-
Task {
168-
let url = URL(string: "https://api.github.com/repos/ProStore-iOS/certificates/git/trees/main")!
169-
do {
170-
let (data, _) = try await URLSession.shared.data(from: url)
171-
let decoder = JSONDecoder()
172-
let response = try decoder.decode(TreeResponse.self, from: data)
173-
let items = response.tree.filter { $0.type == "tree" }.sorted { $0.path < $1.path }
174-
await MainActor.run {
175-
self.certItems = items
176-
self.isLoadingCerts = false
177-
}
178-
} catch {
179-
await MainActor.run {
180-
self.statusMessage = "Failed to fetch certificates: \(error.localizedDescription)"
181-
self.isLoadingCerts = false
166+
private func fetchTrees() {
167+
Task {
168+
let rootURL = URL(string: "https://api.github.com/repos/ProStore-iOS/certificates/git/trees/main")!
169+
do {
170+
let (data, _) = try await URLSession.shared.data(from: rootURL)
171+
let decoder = JSONDecoder()
172+
let response = try decoder.decode(TreeResponse.self, from: data)
173+
174+
let folders = response.tree.filter { $0.type == "tree" }
175+
176+
var validCerts: [TreeItem] = []
177+
178+
for folder in folders {
179+
guard let folderURL = URL(string: folder.url) else { continue }
180+
let (subData, _) = try await URLSession.shared.data(from: folderURL)
181+
let subTree = try decoder.decode(TreeResponse.self, from: subData).tree
182+
183+
let hasP12 = subTree.contains { $0.path.hasSuffix(".p12") }
184+
let hasProv = subTree.contains { $0.path.hasSuffix(".mobileprovision") }
185+
let hasPassword = subTree.contains { $0.path == "password.txt" }
186+
187+
if hasP12 && hasProv && hasPassword {
188+
validCerts.append(folder)
182189
}
183190
}
191+
192+
await MainActor.run {
193+
self.certItems = validCerts.sorted { $0.path < $1.path }
194+
self.isLoadingCerts = false
195+
}
196+
} catch {
197+
await MainActor.run {
198+
self.statusMessage = "Failed to fetch certificates: \(error.localizedDescription)"
199+
self.isLoadingCerts = false
200+
}
184201
}
185202
}
203+
}
186204

187205
private func fetchBlobContent(url: URL) async throws -> Data {
188206
let (data, _) = try await URLSession.shared.data(from: url)
@@ -283,3 +301,4 @@ struct OfficialCertificatesView: View {
283301
}
284302
}
285303

304+

0 commit comments

Comments
 (0)