Compare commits
3 commits
39f6ff24b3
...
f4db94db27
Author | SHA1 | Date | |
---|---|---|---|
f4db94db27 | |||
9d59c73c59 | |||
756012ee69 |
6 changed files with 38 additions and 15 deletions
|
@ -24,13 +24,14 @@ sea-orm = { version = "0.12", optional = true }
|
||||||
reqwest = { version = "0.12", features = ["json"], optional = true }
|
reqwest = { version = "0.12", features = ["json"], optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["activitypub-miscellaneous-terms"]
|
default = ["activitypub-miscellaneous-terms", "send"]
|
||||||
# extensions
|
# extensions
|
||||||
activitypub-miscellaneous-terms = [] # https://swicg.github.io/miscellany/
|
activitypub-miscellaneous-terms = [] # https://swicg.github.io/miscellany/
|
||||||
activitypub-counters = [] # https://ns.alemi.dev/as/counters/#
|
activitypub-counters = [] # https://ns.alemi.dev/as/counters/#
|
||||||
activitypub-fe = [] # https://ns.alemi.dev/as/fe/#
|
activitypub-fe = [] # https://ns.alemi.dev/as/fe/#
|
||||||
litepub = [] # incomplete, https://litepub.social/
|
litepub = [] # incomplete, https://litepub.social/
|
||||||
# builtin utils
|
# builtin utils
|
||||||
|
send = []
|
||||||
orm = ["dep:sea-orm"]
|
orm = ["dep:sea-orm"]
|
||||||
fetch = ["dep:reqwest"]
|
fetch = ["dep:reqwest"]
|
||||||
# providers
|
# providers
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
#[cfg(feature = "send")]
|
||||||
|
pub trait MaybeSend : Send {}
|
||||||
|
#[cfg(feature = "send")]
|
||||||
|
impl<T : Send> MaybeSend for T {}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(not(feature = "send"))]
|
||||||
|
pub trait MaybeSend {}
|
||||||
|
#[cfg(not(feature = "send"))]
|
||||||
|
impl<T> MaybeSend for T {}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
#[error("invalid type value")]
|
#[error("invalid type value")]
|
||||||
pub struct TypeValueError;
|
pub struct TypeValueError;
|
||||||
|
|
|
@ -116,6 +116,15 @@ impl<T : super::Base> Node<T> {
|
||||||
Node::Array(x) => x.iter().filter_map(Self::id).collect()
|
Node::Array(x) => x.iter().filter_map(Self::id).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn flat(self) -> Vec<Node<T>> {
|
||||||
|
match self {
|
||||||
|
Node::Empty => vec![],
|
||||||
|
Node::Link(_) | Node::Object(_) => vec![self],
|
||||||
|
// i think AP disallows array of arrays so no need to make this recursive
|
||||||
|
Node::Array(arr) => arr.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "unstructured")]
|
#[cfg(feature = "unstructured")]
|
||||||
|
|
|
@ -8,13 +8,13 @@ crate::strenum! {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Base {
|
pub trait Base : crate::macros::MaybeSend {
|
||||||
fn id(&self) -> Option<&str> { None }
|
fn id(&self) -> Option<&str> { None }
|
||||||
fn base_type(&self) -> Option<BaseType> { None }
|
fn base_type(&self) -> Option<BaseType> { None }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub trait BaseMut {
|
pub trait BaseMut : crate::macros::MaybeSend {
|
||||||
fn set_id(self, val: Option<&str>) -> Self;
|
fn set_id(self, val: Option<&str>) -> Self;
|
||||||
fn set_base_type(self, val: Option<BaseType>) -> Self;
|
fn set_base_type(self, val: Option<BaseType>) -> Self;
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,18 @@ impl Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// get bare id, usually an uuid but unspecified
|
||||||
|
pub fn id(&self, uri: &str) -> String {
|
||||||
|
if uri.starts_with(&self.0.domain) {
|
||||||
|
uri.split('/').last().unwrap_or("").to_string()
|
||||||
|
} else {
|
||||||
|
uri
|
||||||
|
.replace("https://", "+")
|
||||||
|
.replace("http://", "+")
|
||||||
|
.replace('/', "@")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// get full user id uri
|
/// get full user id uri
|
||||||
pub fn uid(&self, id: String) -> String {
|
pub fn uid(&self, id: String) -> String {
|
||||||
self.uri("users", id)
|
self.uri("users", id)
|
||||||
|
@ -132,17 +144,6 @@ impl Context {
|
||||||
self.uri("activities", id)
|
self.uri("activities", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get bare id, usually an uuid but unspecified
|
|
||||||
pub fn id(&self, uri: &str) -> String {
|
|
||||||
if uri.starts_with(&self.0.domain) {
|
|
||||||
uri.split('/').last().unwrap_or("").to_string()
|
|
||||||
} else {
|
|
||||||
uri
|
|
||||||
.replace("https://", "+")
|
|
||||||
.replace("http://", "+")
|
|
||||||
.replace('/', "@")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn server(id: &str) -> String {
|
pub fn server(id: &str) -> String {
|
||||||
id
|
id
|
||||||
|
|
|
@ -319,7 +319,7 @@ impl apb::server::Inbox for Context {
|
||||||
// TODO in theory we could work with just object_id but right now only accept embedded
|
// TODO in theory we could work with just object_id but right now only accept embedded
|
||||||
let undone_activity = activity.object().extract().ok_or_else(UpubError::bad_request)?;
|
let undone_activity = activity.object().extract().ok_or_else(UpubError::bad_request)?;
|
||||||
let undone_aid = undone_activity.id().ok_or_else(UpubError::bad_request)?;
|
let undone_aid = undone_activity.id().ok_or_else(UpubError::bad_request)?;
|
||||||
let undone_object_id = undone_activity.object().id().ok_or_else(UpubError::bad_request)?;
|
let undone_object_uri = undone_activity.object().id().ok_or_else(UpubError::bad_request)?;
|
||||||
let activity_type = undone_activity.activity_type().ok_or_else(UpubError::bad_request)?;
|
let activity_type = undone_activity.activity_type().ok_or_else(UpubError::bad_request)?;
|
||||||
let undone_activity_author = undone_activity.actor().id().ok_or_else(UpubError::bad_request)?;
|
let undone_activity_author = undone_activity.actor().id().ok_or_else(UpubError::bad_request)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue