mastodon-ios/Mastodon/Service/APIService/APIService+WebFinger.swift

38 lines
985 B
Swift
Raw Normal View History

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 {
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()
}
}