diff options
author | Colin Reeder <colin@vpzom.click> | 2020-08-08 10:00:24 -0600 |
---|---|---|
committer | Colin Reeder <colin@vpzom.click> | 2020-08-08 10:00:24 -0600 |
commit | 172442061f04b2c9cf0e1c67759c0102c38d0e33 (patch) | |
tree | d961215cd3649669a697fab88d9c0076c907cc69 | |
parent | 52cd2eb9caad792e8c4162a25e08f91f9c5ba63d (diff) |
Support users in actors:lookup
-rw-r--r-- | openapi/openapi.json | 5 | ||||
-rw-r--r-- | res/lang/en.ftl | 1 | ||||
-rw-r--r-- | res/lang/eo.ftl | 1 | ||||
-rw-r--r-- | src/routes/api/mod.rs | 25 |
4 files changed, 16 insertions, 16 deletions
diff --git a/openapi/openapi.json b/openapi/openapi.json index a6df78c..14e313e 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -140,7 +140,7 @@ "paths": { "/api/unstable/actors:lookup/{remoteID}": { "get": { - "summary": "Look up a remote community by WebFinger or ActivityPub ID", + "summary": "Look up a remote actor by WebFinger or ActivityPub ID", "parameters": [ { "name": "remoteID", @@ -162,7 +162,8 @@ "type": "object", "required": ["id"], "properties": { - "id": {"type": "integer"} + "id": {"type": "integer"}, + "type": {"type": "string", "enum": ["community", "user"]} } } } diff --git a/res/lang/en.ftl b/res/lang/en.ftl index 809aeb5..f1f462a 100644 --- a/res/lang/en.ftl +++ b/res/lang/en.ftl @@ -9,7 +9,6 @@ no_such_community = No such community no_such_local_user_by_name = No local user found by that name no_such_post = No such post no_such_user = No such user -not_group = Not a group password_incorrect = Incorrect password post_content_conflict = content_markdown and content_text are mutually exclusive post_href_invalid = Specified URL is not valid diff --git a/res/lang/eo.ftl b/res/lang/eo.ftl index 855af95..51cbdd6 100644 --- a/res/lang/eo.ftl +++ b/res/lang/eo.ftl @@ -9,7 +9,6 @@ no_such_community = Neniu tia komunumo no_such_local_user_by_name = Neniu uzanto trovita per tiu nomo no_such_post = Neniu tia poŝto no_such_user = Neniu tia uzanto -not_group = Ne estas grupo password_incorrect = Pasvorto malĝustas post_content_conflict = content_markdown kaj content_text konfliktas post_href_invalid = URL nevalidas. diff --git a/src/routes/api/mod.rs b/src/routes/api/mod.rs index c90096e..10a47d0 100644 --- a/src/routes/api/mod.rs +++ b/src/routes/api/mod.rs @@ -213,12 +213,11 @@ fn parse_lookup(src: &str) -> Result<Lookup, crate::Error> { async fn route_unstable_actors_lookup( params: (String,), ctx: Arc<crate::RouteContext>, - req: hyper::Request<hyper::Body>, + _req: hyper::Request<hyper::Body>, ) -> Result<hyper::Response<hyper::Body>, crate::Error> { let (query,) = params; println!("lookup {}", query); - let lang = crate::get_lang_for_req(&req); let db = ctx.db_pool.get().await?; let lookup = parse_lookup(&query)?; @@ -277,16 +276,18 @@ async fn route_unstable_actors_lookup( let actor = crate::apub_util::fetch_actor(&uri, &db, &ctx.http_client).await?; - if let crate::apub_util::ActorLocalInfo::Community { id, .. } = actor { - Ok(hyper::Response::builder() - .header(hyper::header::CONTENT_TYPE, "application/json") - .body(serde_json::to_vec(&serde_json::json!([{ "id": id }]))?.into())?) - } else { - Ok(crate::simple_response( - hyper::StatusCode::BAD_REQUEST, - lang.tr("not_group", None).into_owned(), - )) - } + let info = match actor { + crate::apub_util::ActorLocalInfo::Community { id, .. } => { + serde_json::json!({"id": id, "type": "community"}) + } + crate::apub_util::ActorLocalInfo::User { id, .. } => { + serde_json::json!({"id": id, "type": "user"}) + } + }; + + Ok(hyper::Response::builder() + .header(hyper::header::CONTENT_TYPE, "application/json") + .body(serde_json::to_vec(&[info])?.into())?) } async fn route_unstable_logins_create( |