yattee/Model/DataProvider.swift

26 lines
812 B
Swift
Raw Normal View History

2021-06-10 22:50:10 +00:00
import Alamofire
import Foundation
2021-06-14 18:05:02 +00:00
// swiftlint:disable:next final_class
2021-06-10 22:50:10 +00:00
class DataProvider: ObservableObject {
static let instance = "https://invidious.home.arekf.net"
2021-06-14 18:05:02 +00:00
static func proxyURLForAsset(_ url: String) -> URL? {
guard let instanceURLComponents = URLComponents(string: DataProvider.instance),
var urlComponents = URLComponents(string: url) else { return nil }
urlComponents.scheme = instanceURLComponents.scheme
urlComponents.host = instanceURLComponents.host
return urlComponents.url
}
2021-06-11 22:49:42 +00:00
static func request(_ path: String, headers: HTTPHeaders? = nil) -> DataRequest {
AF.request(apiURLString(path), headers: headers)
2021-06-10 22:50:10 +00:00
}
static func apiURLString(_ path: String) -> String {
"\(instance)/api/v1/\(path)"
}
}