2020-03-20 00:55:11 +00:00
|
|
|
use crate::{
|
2020-05-21 21:24:56 +00:00
|
|
|
apub::{PublicKey, PublicKeyInner},
|
2020-03-20 00:55:11 +00:00
|
|
|
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-03-20 00:55:11 +00:00
|
|
|
};
|
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,
|
2020-03-20 00:55:11 +00:00
|
|
|
};
|
2021-02-10 04:17:20 +00:00
|
|
|
use activitystreams_ext::Ext1;
|
2020-03-20 00:55:11 +00:00
|
|
|
use actix_web::{web, Responder};
|
2022-04-08 22:39:38 +00:00
|
|
|
use rsa::pkcs8::EncodePublicKey;
|
2020-03-20 00:55:11 +00:00
|
|
|
|
2021-09-18 17:55:39 +00:00
|
|
|
#[tracing::instrument(name = "Actor")]
|
2021-02-10 04:17:20 +00:00
|
|
|
pub(crate) async fn route(
|
2020-03-20 00:55:11 +00:00
|
|
|
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(
|
2020-06-03 17:37:36 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
2020-03-20 00:55:11 +00:00
|
|
|
|
|
|
|
application
|
2020-06-03 17:37:36 +00:00
|
|
|
.set_id(config.generate_url(UrlKind::Actor))
|
2020-06-03 18:45:17 +00:00
|
|
|
.set_summary("AodeRelay bot")
|
|
|
|
.set_name("AodeRelay")
|
2020-06-03 17:37:36 +00:00
|
|
|
.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")
|
2020-06-03 17:37:36 +00:00
|
|
|
.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 {
|
2020-06-03 17:37:36 +00:00
|
|
|
shared_inbox: Some(config.generate_url(UrlKind::Inbox)),
|
2020-05-21 21:24:56 +00:00
|
|
|
..Default::default()
|
|
|
|
});
|
2020-03-20 00:55:11 +00:00
|
|
|
|
2020-05-21 21:24:56 +00:00
|
|
|
Ok(ok(application))
|
2020-03-20 00:55:11 +00:00
|
|
|
}
|