Subscriptions view

This commit is contained in:
Arkadiusz Fal
2021-06-12 00:49:42 +02:00
parent 4af395d788
commit 65e5f0f426
10 changed files with 78 additions and 60 deletions

View File

@@ -2,8 +2,8 @@ import Foundation
class AppState: ObservableObject {
@Published var showingChannel = false
@Published var channelID: String?
@Published var channel: String?
@Published var channelID: String = ""
@Published var channel: String = ""
func openChannel(from video: Video) {
channel = video.author
@@ -13,7 +13,7 @@ class AppState: ObservableObject {
func closeChannel() {
showingChannel = false
channel = nil
channelID = nil
channel = ""
channelID = ""
}
}

View File

@@ -4,8 +4,8 @@ import Foundation
class DataProvider: ObservableObject {
static let instance = "https://invidious.home.arekf.net"
static func request(_ path: String) -> DataRequest {
AF.request(apiURLString(path))
static func request(_ path: String, headers: HTTPHeaders? = nil) -> DataRequest {
AF.request(apiURLString(path), headers: headers)
}
static func apiURLString(_ path: String) -> String {

View File

@@ -0,0 +1,23 @@
import Alamofire
import Foundation
import SwiftyJSON
class SubscriptionVideosProvider: DataProvider {
@Published var videos = [Video]()
var sid: String = "RpoS7YPPK2-QS81jJF9z4KSQAjmzsOnMpn84c73-GQ8="
func load() {
let headers = HTTPHeaders([HTTPHeader(name: "Cookie", value: "SID=\(sid)")])
DataProvider.request("auth/feed", headers: headers).responseJSON { response in
switch response.result {
case let .success(value):
if let feedVideos = JSON(value).dictionaryValue["videos"] {
self.videos = feedVideos.arrayValue.map { Video($0) }
}
case let .failure(error):
print(error)
}
}
}
}