forked from alemi/upub
feat: more link helpers and node constructors
This commit is contained in:
parent
bf8cd97c8f
commit
a5c51f00ea
2 changed files with 34 additions and 7 deletions
|
@ -2,12 +2,23 @@ pub mod user;
|
|||
pub mod object;
|
||||
pub mod activity;
|
||||
|
||||
|
||||
use axum::{extract::State, http::StatusCode, Json};
|
||||
use sea_orm::{EntityTrait, IntoActiveModel};
|
||||
|
||||
use crate::{activitystream::{self, object::{activity::{Activity, ActivityType}, actor::{ActorMut, ActorType}, ObjectMut, ObjectType}, Base, BaseMut, BaseType, Node}, model, server::Context, url};
|
||||
|
||||
pub const PUBLIC_TARGET : &str = "https://www.w3.org/ns/activitystreams#Public";
|
||||
|
||||
pub fn split_id(id: &str) -> (String, String) {
|
||||
let clean = id
|
||||
.replace("http://", "")
|
||||
.replace("https://", "");
|
||||
let mut splits = clean.split('/');
|
||||
let first = splits.next().unwrap_or("");
|
||||
let last = splits.last().unwrap_or(first);
|
||||
(first.to_string(), last.to_string())
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
// TODO i don't really like how pleroma/mastodon do it actually, maybe change this?
|
||||
|
|
|
@ -85,8 +85,28 @@ impl<T : super::Base> Node<T> {
|
|||
}
|
||||
|
||||
impl Node<serde_json::Value>{
|
||||
pub fn link(uri: &str) -> Self {
|
||||
Node::Link(Box::new(uri.to_string()))
|
||||
pub fn empty() -> Self {
|
||||
Node::Empty
|
||||
}
|
||||
|
||||
pub fn link(uri: String) -> Self {
|
||||
Node::Link(Box::new(uri))
|
||||
}
|
||||
|
||||
pub fn links(uris: Vec<String>) -> Self {
|
||||
Node::Array(
|
||||
uris
|
||||
.into_iter()
|
||||
.map(Node::link)
|
||||
.collect()
|
||||
)
|
||||
}
|
||||
|
||||
pub fn maybe_link(uri: Option<String>) -> Self {
|
||||
match uri {
|
||||
Some(uri) => Node::Link(Box::new(uri)),
|
||||
None => Node::Empty,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn object(x: serde_json::Value) -> Self {
|
||||
|
@ -146,7 +166,3 @@ impl From<serde_json::Value> for Node<serde_json::Value> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue