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,
|
2020-03-20 00:55:11 +00:00
|
|
|
error::MyError,
|
2020-03-23 17:38:39 +00:00
|
|
|
routes::ok,
|
2020-03-20 00:55:11 +00:00
|
|
|
};
|
2020-05-21 21:24:56 +00:00
|
|
|
use activitystreams_ext::Ext1;
|
|
|
|
use activitystreams_new::{
|
|
|
|
actor::{ApActor, Application, Endpoints},
|
|
|
|
context,
|
|
|
|
prelude::*,
|
|
|
|
primitives::{XsdAnyUri, XsdString},
|
|
|
|
security,
|
2020-03-20 00:55:11 +00:00
|
|
|
};
|
|
|
|
use actix_web::{web, Responder};
|
|
|
|
use rsa_pem::KeyExt;
|
|
|
|
|
|
|
|
pub async fn route(
|
|
|
|
state: web::Data<State>,
|
|
|
|
config: web::Data<Config>,
|
|
|
|
) -> Result<impl Responder, MyError> {
|
2020-05-21 21:24:56 +00:00
|
|
|
let mut application = Ext1::new(
|
|
|
|
ApActor::new(
|
|
|
|
config.generate_url(UrlKind::Inbox).parse()?,
|
|
|
|
Application::new(),
|
|
|
|
),
|
|
|
|
PublicKey {
|
|
|
|
public_key: PublicKeyInner {
|
|
|
|
id: config.generate_url(UrlKind::MainKey).parse()?,
|
|
|
|
owner: config.generate_url(UrlKind::Actor).parse()?,
|
|
|
|
public_key_pem: state.public_key.to_pem_pkcs8()?,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
2020-03-20 00:55:11 +00:00
|
|
|
|
|
|
|
application
|
2020-05-21 21:24:56 +00:00
|
|
|
.set_id(config.generate_url(UrlKind::Actor).parse()?)
|
|
|
|
.set_summary(XsdString::from("AodeRelay bot"))
|
|
|
|
.set_name(XsdString::from("AodeRelay"))
|
|
|
|
.set_url(config.generate_url(UrlKind::Actor).parse::<XsdAnyUri>()?)
|
|
|
|
.set_many_contexts(vec![context(), security()])
|
|
|
|
.set_preferred_username("relay".into())
|
2020-05-21 22:29:18 +00:00
|
|
|
.set_outbox(config.generate_url(UrlKind::Outbox).parse()?)
|
2020-05-21 21:24:56 +00:00
|
|
|
.set_followers(
|
|
|
|
config
|
|
|
|
.generate_url(UrlKind::Followers)
|
|
|
|
.parse::<XsdAnyUri>()?,
|
|
|
|
)
|
|
|
|
.set_following(
|
|
|
|
config
|
|
|
|
.generate_url(UrlKind::Following)
|
|
|
|
.parse::<XsdAnyUri>()?,
|
|
|
|
)
|
|
|
|
.set_endpoints(Endpoints {
|
|
|
|
shared_inbox: Some(config.generate_url(UrlKind::Inbox).parse::<XsdAnyUri>()?),
|
|
|
|
..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
|
|
|
}
|