-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
e9d9b9b
commit 403e004
Showing
1 changed file
with
16 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: []) | ||
} | ||
|
||
|
@@ -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 { | ||
|
@@ -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)") | ||
|