2021-07-08 08:17:35 +02:00
|
|
|
//
|
|
|
|
// APIService+WebFinger.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-7-8.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Combine
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
|
|
|
import CommonOSLog
|
|
|
|
import DateToolsSwift
|
|
|
|
import MastodonSDK
|
|
|
|
|
|
|
|
extension APIService {
|
|
|
|
|
|
|
|
private static func webFingerEndpointURL(domain: String) -> URL {
|
2022-03-15 19:02:28 +01:00
|
|
|
|
|
|
|
return URL(string: "\(URL.httpScheme(domain: domain))://\(domain)/")!
|
2021-07-08 08:17:35 +02:00
|
|
|
.appendingPathComponent(".well-known")
|
|
|
|
.appendingPathComponent("webfinger")
|
|
|
|
}
|
|
|
|
|
|
|
|
func webFinger(
|
|
|
|
domain: String
|
|
|
|
) -> AnyPublisher<String, Error> {
|
|
|
|
let url = APIService.webFingerEndpointURL(domain: domain)
|
|
|
|
let request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 3)
|
|
|
|
return session.dataTaskPublisher(for: request)
|
|
|
|
.tryMap { data, response in
|
|
|
|
return response.url?.host ?? domain
|
|
|
|
}
|
|
|
|
.eraseToAnyPublisher()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|