~vpzom/lotide

172442061f04b2c9cf0e1c67759c0102c38d0e33 — Colin Reeder 9 months ago 52cd2eb
Support users in actors:lookup
4 files changed, 16 insertions(+), 16 deletions(-)

M openapi/openapi.json
M res/lang/en.ftl
M res/lang/eo.ftl
M src/routes/api/mod.rs
M openapi/openapi.json => openapi/openapi.json +3 -2
@@ 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"]}
										}
									}
								}

M res/lang/en.ftl => res/lang/en.ftl +0 -1
@@ 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

M res/lang/eo.ftl => res/lang/eo.ftl +0 -1
@@ 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.

M src/routes/api/mod.rs => src/routes/api/mod.rs +13 -12
@@ 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(