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] 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 )! )