mirror of https://github.com/LemmyNet/lemmy
move library code to separate crate (most of it)
parent
b605057e85
commit
dfce4b67ca
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "lemmy_apub_lib"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
lemmy_utils = { path = "../utils" }
|
||||
lemmy_websocket = { path = "../websocket" }
|
||||
activitystreams = "0.7.0-alpha.11"
|
||||
activitystreams-ext = "0.1.0-alpha.2"
|
||||
serde = { version = "1.0.123", features = ["derive"] }
|
||||
async-trait = "0.1.42"
|
||||
url = { version = "2.2.1", features = ["serde"] }
|
@ -0,0 +1,66 @@
|
||||
use activitystreams::{
|
||||
error::DomainError,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use std::marker::PhantomData;
|
||||
use url::Url;
|
||||
|
||||
// for now, limit it to activity routing only, no http sigs, parsing or any of that
|
||||
// need to route in this order:
|
||||
// 1. recipient actor
|
||||
// 2. activity type
|
||||
// 3. inner object (recursively until object is empty or an url)
|
||||
|
||||
// TODO: turn this into a trait in which app has to implement the following functions:
|
||||
// .checkIdValid() - for unique, instance block etc
|
||||
// .checkHttpSig::<RequestType>()
|
||||
// .fetchObject() - for custom http client
|
||||
// .checkActivity() - for common validity checks
|
||||
pub struct InboxConfig {
|
||||
//actors: Vec<ActorConfig>,
|
||||
}
|
||||
|
||||
impl InboxConfig {
|
||||
pub fn shared_inbox_handler() {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
|
||||
pub enum PublicUrl {
|
||||
#[serde(rename = "https://www.w3.org/ns/activitystreams#Public")]
|
||||
Public,
|
||||
}
|
||||
|
||||
pub fn verify_domains_match(a: &Url, b: &Url) -> Result<(), LemmyError> {
|
||||
if a.domain() != b.domain() {
|
||||
return Err(DomainError.into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// todo: later add a similar trait SendActivity
|
||||
// todo: maybe add a separate method verify()
|
||||
#[async_trait::async_trait(?Send)]
|
||||
pub trait ReceiveActivity {
|
||||
// todo: later handle request_counter completely inside library
|
||||
async fn receive(
|
||||
&self,
|
||||
context: &LemmyContext,
|
||||
request_counter: &mut i32,
|
||||
) -> Result<(), LemmyError>;
|
||||
}
|
||||
|
||||
// todo: instead of phantomdata, might use option<kind> to cache the fetched object (or just fetch on construction)
|
||||
pub struct ObjectId<'a, Kind>(Url, &'a PhantomData<Kind>);
|
||||
|
||||
impl<Kind> ObjectId<'_, Kind> {
|
||||
pub fn url(self) -> Url {
|
||||
self.0
|
||||
}
|
||||
pub fn dereference(self) -> Result<Kind, LemmyError> {
|
||||
// todo: fetch object from http or database
|
||||
todo!()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue