Share button

This commit is contained in:
Arkadiusz Fal
2021-10-27 00:59:59 +02:00
parent b50d915d8e
commit 544dc70c5d
11 changed files with 205 additions and 19 deletions

View File

@@ -2,6 +2,7 @@ import Foundation
import Siesta
protocol VideosAPI {
var account: Account! { get }
var signedIn: Bool { get }
func channel(_ id: String) -> Resource
@@ -25,6 +26,7 @@ protocol VideosAPI {
func channelPlaylist(_ id: String) -> Resource?
func loadDetails(_ item: PlayerQueueItem, completionHandler: @escaping (PlayerQueueItem) -> Void)
func shareURL(_ item: ContentItem) -> URL
}
extension VideosAPI {
@@ -45,4 +47,21 @@ extension VideosAPI {
completionHandler(newItem)
}
}
func shareURL(_ item: ContentItem) -> URL {
var urlComponents = account.instance.urlComponents
urlComponents.host = account.instance.frontendHost
switch item.contentType {
case .video:
urlComponents.path = "/watch"
urlComponents.query = "v=\(item.video.videoID)"
case .channel:
urlComponents.path = "/channel/\(item.channel.id)"
case .playlist:
urlComponents.path = "/playlist"
urlComponents.query = "list=\(item.playlist.id)"
}
return urlComponents.url!
}
}