Adding shorthand federated object searching.

This commit is contained in:
Dessalines 2020-04-29 12:55:54 -04:00
parent 6632d610c4
commit 906f34ff2d
2 changed files with 14 additions and 4 deletions

View file

@ -45,11 +45,19 @@ pub enum SearchAcceptedObjects {
/// Attempt to parse the query as URL, and fetch an ActivityPub object from it. /// Attempt to parse the query as URL, and fetch an ActivityPub object from it.
/// ///
/// Some working examples for use with the docker/federation/ setup: /// Some working examples for use with the docker/federation/ setup:
/// http://lemmy_alpha:8540/c/main /// http://lemmy_alpha:8540/c/main, or /c/main@lemmy_alpha:8540
/// http://lemmy_alpha:8540/u/lemmy_alpha /// http://lemmy_alpha:8540/u/lemmy_alpha, or /u/lemmy_alpha@lemmy_alpha:8540
/// http://lemmy_alpha:8540/p/3 /// http://lemmy_alpha:8540/p/3
pub fn search_by_apub_id(query: &str, conn: &PgConnection) -> Result<SearchResponse, Error> { pub fn search_by_apub_id(query: &str, conn: &PgConnection) -> Result<SearchResponse, Error> {
let query_url = Url::parse(&query)?; // Parse the shorthand query url
let query_url = if query.contains('@') {
let split = query.split('@').collect::<Vec<&str>>();
let url = format!("{}://{}{}", get_apub_protocol_string(), split[1], split[0]);
Url::parse(&url)?
} else {
Url::parse(&query)?
};
let mut response = SearchResponse { let mut response = SearchResponse {
type_: SearchType::All.to_string(), type_: SearchType::All.to_string(),
comments: vec![], comments: vec![],

View file

@ -95,7 +95,9 @@ describe('main', () => {
describe('follow_accept', () => { describe('follow_accept', () => {
test('/u/lemmy_alpha follows and accepts lemmy_beta/c/main', async () => { test('/u/lemmy_alpha follows and accepts lemmy_beta/c/main', async () => {
// Make sure lemmy_beta/c/main is cached on lemmy_alpha // 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, { let searchResponse: SearchResponse = await fetch(searchUrl, {
method: 'GET', method: 'GET',
}).then(d => d.json()); }).then(d => d.json());