1
0
Fork 0
forked from alemi/upub

feat: more link helpers and node constructors

This commit is contained in:
əlemi 2024-03-21 00:04:44 +01:00
parent bf8cd97c8f
commit a5c51f00ea
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 34 additions and 7 deletions

View file

@ -2,12 +2,23 @@ pub mod user;
pub mod object; pub mod object;
pub mod activity; pub mod activity;
use axum::{extract::State, http::StatusCode, Json}; use axum::{extract::State, http::StatusCode, Json};
use sea_orm::{EntityTrait, IntoActiveModel}; 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}; 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)] #[derive(Debug, serde::Deserialize)]
// TODO i don't really like how pleroma/mastodon do it actually, maybe change this? // TODO i don't really like how pleroma/mastodon do it actually, maybe change this?

View file

@ -85,8 +85,28 @@ impl<T : super::Base> Node<T> {
} }
impl Node<serde_json::Value>{ impl Node<serde_json::Value>{
pub fn link(uri: &str) -> Self { pub fn empty() -> Self {
Node::Link(Box::new(uri.to_string())) 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 { pub fn object(x: serde_json::Value) -> Self {
@ -146,7 +166,3 @@ impl From<serde_json::Value> for Node<serde_json::Value> {
} }
} }