mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-11 07:43:28 +01:00
XCode project for app, moved app project to folder
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// FetchTrustedSourcesOperation.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 4/13/22.
|
||||
// Copyright © 2022 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
private extension URL {
|
||||
#if STAGING
|
||||
static let trustedSources = URL(string: "https://raw.githubusercontent.com/SideStore/SideStore/develop/trustedapps.json")!
|
||||
#else
|
||||
static let trustedSources = URL(string: "https://raw.githubusercontent.com/SideStore/SideStore/develop/trustedapps.json")!
|
||||
#endif
|
||||
}
|
||||
|
||||
public extension FetchTrustedSourcesOperation {
|
||||
public struct TrustedSource: Decodable {
|
||||
public var identifier: String
|
||||
public var sourceURL: URL?
|
||||
}
|
||||
|
||||
private struct Response: Decodable {
|
||||
var version: Int
|
||||
var sources: [FetchTrustedSourcesOperation.TrustedSource]
|
||||
}
|
||||
}
|
||||
|
||||
public final class FetchTrustedSourcesOperation: ResultOperation<[FetchTrustedSourcesOperation.TrustedSource]> {
|
||||
public override func main() {
|
||||
super.main()
|
||||
|
||||
let dataTask = URLSession.shared.dataTask(with: .trustedSources) { data, response, error in
|
||||
do {
|
||||
if let response = response as? HTTPURLResponse {
|
||||
guard response.statusCode != 404 else {
|
||||
self.finish(.failure(URLError(.fileDoesNotExist, userInfo: [NSURLErrorKey: URL.trustedSources])))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
guard let data = data else { throw error! }
|
||||
|
||||
let response = try Foundation.JSONDecoder().decode(Response.self, from: data)
|
||||
self.finish(.success(response.sources))
|
||||
} catch {
|
||||
self.finish(.failure(error))
|
||||
}
|
||||
}
|
||||
|
||||
dataTask.resume()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user