Merge pull request #627 from 0x000C/bugfix/619

Fix #619: Remove ports from shared YouTube links
This commit is contained in:
Arkadiusz Fal 2024-05-16 18:25:35 +02:00 committed by GitHub
commit db2417e455
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 9 deletions

View File

@ -66,7 +66,7 @@ protocol VideosAPI {
failureHandler: ((RequestError) -> Void)?, failureHandler: ((RequestError) -> Void)?,
completionHandler: @escaping (PlayerQueueItem) -> Void completionHandler: @escaping (PlayerQueueItem) -> Void
) )
func shareURL(_ item: ContentItem, frontendHost: String?, time: CMTime?) -> URL? func shareURL(_ item: ContentItem, frontendURL: String?, time: CMTime?) -> URL?
func comments(_ id: Video.ID, page: String?) -> Resource? func comments(_ id: Video.ID, page: String?) -> Resource?
} }
@ -108,14 +108,18 @@ extension VideosAPI {
.onFailure { failureHandler?($0) } .onFailure { failureHandler?($0) }
} }
func shareURL(_ item: ContentItem, frontendHost: String? = nil, time: CMTime? = nil) -> URL? { func shareURL(_ item: ContentItem, frontendURLString: String? = nil, time: CMTime? = nil) -> URL? {
guard let frontendHost = frontendHost ?? account?.instance?.frontendHost, var urlComponents: URLComponents?
var urlComponents = account?.instance?.urlComponents if let frontendURLString,
else { let frontendURL = URL(string: frontendURLString) {
return nil urlComponents = URLComponents(URL: frontendURL, resolvingAgainstBaseURL: false)
} else if let instanceComponents = account?.instance?.urlComponents {
urlComponents = instanceComponents
} }
urlComponents.host = frontendHost guard var urlComponents else {
return nil
}
var queryItems = [URLQueryItem]() var queryItems = [URLQueryItem]()

View File

@ -77,7 +77,7 @@ struct ShareButton<LabelView: View>: View {
private var youtubeActions: some View { private var youtubeActions: some View {
Group { Group {
if let url = accounts.api.shareURL(contentItem, frontendHost: "www.youtube.com") { if let url = accounts.api.shareURL(contentItem, frontendURL: "https://www.youtube.com") {
Button(labelForShareURL("YouTube")) { Button(labelForShareURL("YouTube")) {
shareAction(url) shareAction(url)
} }
@ -87,7 +87,7 @@ struct ShareButton<LabelView: View>: View {
shareAction( shareAction(
accounts.api.shareURL( accounts.api.shareURL(
contentItem, contentItem,
frontendHost: "www.youtube.com", frontendURL: "https://www.youtube.com",
time: player.backend.currentTime time: player.backend.currentTime
)! )!
) )