From 1c7da30caffeddf6fae843c3924f7e9a6e1097ba Mon Sep 17 00:00:00 2001 From: 0x000C <44306472+0x000C@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:58:16 -0700 Subject: [PATCH 1/5] fix: Remove ports from shared YouTube links --- Model/Applications/VideosAPI.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Model/Applications/VideosAPI.swift b/Model/Applications/VideosAPI.swift index b84b3c64..ee9e0fbe 100644 --- a/Model/Applications/VideosAPI.swift +++ b/Model/Applications/VideosAPI.swift @@ -117,6 +117,10 @@ extension VideosAPI { urlComponents.host = frontendHost + if frontendHost.contains("youtube.com") { + urlComponents.port = nil + } + var queryItems = [URLQueryItem]() switch item.contentType { From 6ec516dc3d6568ceb0a012526c32d248845cbe70 Mon Sep 17 00:00:00 2001 From: 0x000C <44306472+0x000C@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:58:16 -0700 Subject: [PATCH 2/5] fix: Remove ports from shared YouTube links Fix #619: Remove ports from shared YouTube links --- Model/Applications/VideosAPI.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Model/Applications/VideosAPI.swift b/Model/Applications/VideosAPI.swift index b84b3c64..ee9e0fbe 100644 --- a/Model/Applications/VideosAPI.swift +++ b/Model/Applications/VideosAPI.swift @@ -117,6 +117,10 @@ extension VideosAPI { urlComponents.host = frontendHost + if frontendHost.contains("youtube.com") { + urlComponents.port = nil + } + var queryItems = [URLQueryItem]() switch item.contentType { From 1f667818dbb3c6dd6c931209ce2374e856698454 Mon Sep 17 00:00:00 2001 From: 0x000C <44306472+0x000C@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:21:26 -0700 Subject: [PATCH 3/5] Change shareURL() in VideosAPI and callers to use URLs instead of hostnames --- Model/Applications/VideosAPI.swift | 22 +++++++++++----------- Shared/Views/ShareButton.swift | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Model/Applications/VideosAPI.swift b/Model/Applications/VideosAPI.swift index ee9e0fbe..50e0eca6 100644 --- a/Model/Applications/VideosAPI.swift +++ b/Model/Applications/VideosAPI.swift @@ -66,7 +66,7 @@ protocol VideosAPI { failureHandler: ((RequestError) -> 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? } @@ -108,17 +108,17 @@ extension VideosAPI { .onFailure { failureHandler?($0) } } - func shareURL(_ item: ContentItem, frontendHost: String? = nil, time: CMTime? = nil) -> URL? { - guard let frontendHost = frontendHost ?? account?.instance?.frontendHost, - var urlComponents = account?.instance?.urlComponents - else { - return nil + func shareURL(_ item: ContentItem, frontendURL: String? = nil, time: CMTime? = nil) -> URL? { + var urlComponents: URLComponents? + if let frontendURLString: String = frontendURL, + let frontendURL: URL = URL(string: frontendURLString) { + urlComponents = URLComponents(URL: frontendURL, resolvingAgainstBaseURL: false) + } else if let instanceComponents = account?.instance?.urlComponents { + urlComponents = instanceComponents } - - urlComponents.host = frontendHost - - if frontendHost.contains("youtube.com") { - urlComponents.port = nil + + guard var urlComponents: URLComponents = urlComponents else { + return nil } var queryItems = [URLQueryItem]() diff --git a/Shared/Views/ShareButton.swift b/Shared/Views/ShareButton.swift index 69451b92..9aa716ff 100644 --- a/Shared/Views/ShareButton.swift +++ b/Shared/Views/ShareButton.swift @@ -77,7 +77,7 @@ struct ShareButton: View { private var youtubeActions: some View { 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")) { shareAction(url) } @@ -87,7 +87,7 @@ struct ShareButton: View { shareAction( accounts.api.shareURL( contentItem, - frontendHost: "www.youtube.com", + frontendURL: "https://www.youtube.com", time: player.backend.currentTime )! ) From 4038f7fdb94a65be97955da11b497c228c209510 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Thu, 16 May 2024 18:25:08 +0200 Subject: [PATCH 4/5] Update Model/Applications/VideosAPI.swift --- Model/Applications/VideosAPI.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Model/Applications/VideosAPI.swift b/Model/Applications/VideosAPI.swift index 50e0eca6..32c3d098 100644 --- a/Model/Applications/VideosAPI.swift +++ b/Model/Applications/VideosAPI.swift @@ -108,10 +108,10 @@ extension VideosAPI { .onFailure { failureHandler?($0) } } - func shareURL(_ item: ContentItem, frontendURL: String? = nil, time: CMTime? = nil) -> URL? { + func shareURL(_ item: ContentItem, frontendURLString: String? = nil, time: CMTime? = nil) -> URL? { var urlComponents: URLComponents? - if let frontendURLString: String = frontendURL, - let frontendURL: URL = URL(string: frontendURLString) { + if let frontendURLString, + let frontendURL = URL(string: frontendURLString) { urlComponents = URLComponents(URL: frontendURL, resolvingAgainstBaseURL: false) } else if let instanceComponents = account?.instance?.urlComponents { urlComponents = instanceComponents From 7f8aa51c783dde1fd7c9be3fc9007964a3d419e3 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Thu, 16 May 2024 18:25:15 +0200 Subject: [PATCH 5/5] Update Model/Applications/VideosAPI.swift --- Model/Applications/VideosAPI.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/Applications/VideosAPI.swift b/Model/Applications/VideosAPI.swift index 32c3d098..e4856b47 100644 --- a/Model/Applications/VideosAPI.swift +++ b/Model/Applications/VideosAPI.swift @@ -117,7 +117,7 @@ extension VideosAPI { urlComponents = instanceComponents } - guard var urlComponents: URLComponents = urlComponents else { + guard var urlComponents else { return nil }