From: Dessalines Date: Wed, 29 Apr 2020 16:55:54 +0000 (-0400) Subject: Adding shorthand federated object searching. X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%24%7B%60data:application/static/%7B%60https:/%7Bthis.props.icon%7D?a=commitdiff_plain;h=8cd68f56aa084f3c2e0affee50b8f57a1f4907bf;p=lemmy.git Adding shorthand federated object searching. --- diff --git a/server/src/apub/fetcher.rs b/server/src/apub/fetcher.rs index e07e410b..2164dec8 100644 --- a/server/src/apub/fetcher.rs +++ b/server/src/apub/fetcher.rs @@ -45,11 +45,19 @@ pub enum SearchAcceptedObjects { /// Attempt to parse the query as URL, and fetch an ActivityPub object from it. /// /// Some working examples for use with the docker/federation/ setup: -/// http://lemmy_alpha:8540/c/main -/// http://lemmy_alpha:8540/u/lemmy_alpha +/// http://lemmy_alpha:8540/c/main, or /c/main@lemmy_alpha:8540 +/// http://lemmy_alpha:8540/u/lemmy_alpha, or /u/lemmy_alpha@lemmy_alpha:8540 /// http://lemmy_alpha:8540/p/3 pub fn search_by_apub_id(query: &str, conn: &PgConnection) -> Result { - let query_url = Url::parse(&query)?; + // Parse the shorthand query url + let query_url = if query.contains('@') { + let split = query.split('@').collect::>(); + let url = format!("{}://{}{}", get_apub_protocol_string(), split[1], split[0]); + Url::parse(&url)? + } else { + Url::parse(&query)? + }; + let mut response = SearchResponse { type_: SearchType::All.to_string(), comments: vec![], diff --git a/ui/src/api_tests/api.spec.ts b/ui/src/api_tests/api.spec.ts index ffc33888..7a810d9a 100644 --- a/ui/src/api_tests/api.spec.ts +++ b/ui/src/api_tests/api.spec.ts @@ -95,7 +95,9 @@ describe('main', () => { describe('follow_accept', () => { test('/u/lemmy_alpha follows and accepts lemmy_beta/c/main', async () => { // Make sure lemmy_beta/c/main is cached on lemmy_alpha - let searchUrl = `${lemmyAlphaApiUrl}/search?q=http://lemmy_beta:8550/c/main&type_=All&sort=TopAll`; + // Use short-hand search url + let searchUrl = `${lemmyAlphaApiUrl}/search?q=/c/main@lemmy_beta:8550&type_=All&sort=TopAll`; + let searchResponse: SearchResponse = await fetch(searchUrl, { method: 'GET', }).then(d => d.json());