1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 23:00:32 +05:30
yattee/Model/DataProvider.swift
2021-06-14 20:05:02 +02:00

26 lines
812 B
Swift

import Alamofire
import Foundation
// swiftlint:disable:next final_class
class DataProvider: ObservableObject {
static let instance = "https://invidious.home.arekf.net"
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
}
static func request(_ path: String, headers: HTTPHeaders? = nil) -> DataRequest {
AF.request(apiURLString(path), headers: headers)
}
static func apiURLString(_ path: String) -> String {
"\(instance)/api/v1/\(path)"
}
}