Skip to content

Commit

Permalink
#32 Add more logs during profile download (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
mczachurski authored Apr 12, 2024
1 parent e9d9b9b commit 403e004
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions Sources/VernissageServer/Services/SearchService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ final class SearchService: SearchServiceType {
}

// Search user profile by remote webfinger.
guard let activityPubProfile = await self.getActivityPubProfile(query: query, baseUrl: baseUrl) else {
request.logger.warning("ActivityPub profile URL cannot be downloaded: '\(baseUrl)'.")
guard let activityPubProfile = await self.getActivityPubProfile(query: query, baseUrl: baseUrl, on: request.application) else {
request.logger.warning("ActivityPub profile '\(query)' cannot be downloaded from: '\(baseUrl)'.")
return SearchResultDto(users: [])
}

Expand Down Expand Up @@ -281,17 +281,20 @@ final class SearchService: SearchServiceType {
}
}

private func getActivityPubProfile(query: String, baseUrl: URL) async -> String? {
let activityPubClient = ActivityPubClient()
guard let webfingerResult = try? await activityPubClient.webfinger(baseUrl: baseUrl, resource: query) else {
return nil
}

guard let activityPubProfile = webfingerResult.links.first(where: { $0.rel == "self" })?.href else {
private func getActivityPubProfile(query: String, baseUrl: URL, on application: Application) async -> String? {
do {
let activityPubClient = ActivityPubClient()
let webfingerResult = try await activityPubClient.webfinger(baseUrl: baseUrl, resource: query)

guard let activityPubProfile = webfingerResult.links.first(where: { $0.rel == "self" })?.href else {
return nil
}

return activityPubProfile
} catch {
application.logger.warning("Error during downloading user profile '\(query)' from '\(baseUrl)'. Network error: '\(error.localizedDescription)'.")
return nil
}

return activityPubProfile
}

private func existsInInstanceBlockedList(url: URL, on request: Request) async -> Bool {
Expand All @@ -301,6 +304,8 @@ final class SearchService: SearchServiceType {
return exists ?? false
}

// [email protected]

private func getBaseUrl(from query: String) -> URL? {
let domainFromQuery = query.split(separator: "@").last ?? ""
return URL(string: "https://\(domainFromQuery)")
Expand Down

0 comments on commit 403e004

Please sign in to comment.