summaryrefslogtreecommitdiffstats
path: root/server/src/apub
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-04-29 12:55:54 -0400
committerDessalines <tyhou13@gmx.com>2020-04-29 12:55:54 -0400
commit8cd68f56aa084f3c2e0affee50b8f57a1f4907bf (patch)
treed2922fa4875dcf57d08f3bab50224dad3f20cfc0 /server/src/apub
parent36d0e34668b94a955306a4b83947deb1f10689f2 (diff)
Adding shorthand federated object searching.
Diffstat (limited to 'server/src/apub')
-rw-r--r--server/src/apub/fetcher.rs14
1 files changed, 11 insertions, 3 deletions
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<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 {
type_: SearchType::All.to_string(),
comments: vec![],