relay/src/routes/actor.rs

53 lines
1.6 KiB
Rust
Raw Normal View History

use crate::{
2020-05-21 21:24:56 +00:00
apub::{PublicKey, PublicKeyInner},
config::{Config, UrlKind},
2020-03-23 22:17:53 +00:00
data::State,
2021-09-18 17:55:39 +00:00
error::Error,
2020-03-23 17:38:39 +00:00
routes::ok,
};
2020-09-07 21:51:02 +00:00
use activitystreams::{
2020-05-21 21:24:56 +00:00
actor::{ApActor, Application, Endpoints},
context,
prelude::*,
security,
};
2021-02-10 04:17:20 +00:00
use activitystreams_ext::Ext1;
use actix_web::{web, Responder};
2022-04-08 22:39:38 +00:00
use rsa::pkcs8::EncodePublicKey;
2022-11-01 20:57:33 +00:00
#[tracing::instrument(name = "Actor", skip(config, state))]
2021-02-10 04:17:20 +00:00
pub(crate) async fn route(
state: web::Data<State>,
config: web::Data<Config>,
2021-09-18 17:55:39 +00:00
) -> Result<impl Responder, Error> {
2020-05-21 21:24:56 +00:00
let mut application = Ext1::new(
ApActor::new(config.generate_url(UrlKind::Inbox), Application::new()),
2020-05-21 21:24:56 +00:00
PublicKey {
public_key: PublicKeyInner {
2021-11-23 22:19:59 +00:00
id: config.generate_url(UrlKind::MainKey),
owner: config.generate_url(UrlKind::Actor),
2022-04-08 22:39:38 +00:00
public_key_pem: state
.public_key
.to_public_key_pem(rsa::pkcs8::LineEnding::default())?,
2020-05-21 21:24:56 +00:00
},
},
);
application
.set_id(config.generate_url(UrlKind::Actor))
2020-06-03 18:45:17 +00:00
.set_summary("AodeRelay bot")
.set_name("AodeRelay")
.set_url(config.generate_url(UrlKind::Actor))
2020-05-21 21:24:56 +00:00
.set_many_contexts(vec![context(), security()])
2020-06-03 18:45:17 +00:00
.set_preferred_username("relay")
.set_outbox(config.generate_url(UrlKind::Outbox))
.set_followers(config.generate_url(UrlKind::Followers))
.set_following(config.generate_url(UrlKind::Following))
2020-05-21 21:24:56 +00:00
.set_endpoints(Endpoints {
shared_inbox: Some(config.generate_url(UrlKind::Inbox)),
2020-05-21 21:24:56 +00:00
..Default::default()
});
2020-05-21 21:24:56 +00:00
Ok(ok(application))
}