1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-16 07:10:31 +05:30
yattee/Model/DataProvider.swift

26 lines
812 B
Swift
Raw Normal View History

2021-06-11 04:20:10 +05:30
import Alamofire
import Foundation
2021-06-14 23:35:02 +05:30
// swiftlint:disable:next final_class
2021-06-11 04:20:10 +05:30
class DataProvider: ObservableObject {
static let instance = "https://invidious.home.arekf.net"
2021-06-14 23:35:02 +05:30
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-12 04:19:42 +05:30
static func request(_ path: String, headers: HTTPHeaders? = nil) -> DataRequest {
AF.request(apiURLString(path), headers: headers)
2021-06-11 04:20:10 +05:30
}
static func apiURLString(_ path: String) -> String {
"\(instance)/api/v1/\(path)"
}
}