forked from alemi/upub
64 lines
2.6 KiB
Rust
64 lines
2.6 KiB
Rust
use sea_orm::IntoActiveModel;
|
|
|
|
use crate::{activitypub::PUBLIC_TARGET, activitystream::object::actor::Actor, model::activity::Audience};
|
|
|
|
pub mod user;
|
|
pub mod object;
|
|
pub mod activity;
|
|
|
|
#[derive(Debug, Clone, thiserror::Error)]
|
|
#[error("missing required field: '{0}'")]
|
|
pub struct FieldError(pub &'static str);
|
|
|
|
pub async fn faker(db: &sea_orm::DatabaseConnection, domain: String) -> Result<(), sea_orm::DbErr> {
|
|
use sea_orm::{EntityTrait, Set};
|
|
|
|
let root = user::Model {
|
|
id: format!("{domain}/users/root"),
|
|
name: "root".into(),
|
|
domain: crate::activitypub::domain(&domain),
|
|
preferred_username: Some("Administrator".to_string()),
|
|
summary: Some("hello world! i'm manually generated but served dynamically from db!".to_string()),
|
|
following: None,
|
|
followers: None,
|
|
icon: Some("https://cdn.alemi.dev/social/circle-square.png".to_string()),
|
|
image: Some("https://cdn.alemi.dev/social/someriver-xs.jpg".to_string()),
|
|
inbox: None,
|
|
shared_inbox: None,
|
|
outbox: None,
|
|
actor_type: super::activitystream::object::actor::ActorType::Person,
|
|
created: chrono::Utc::now(),
|
|
updated: chrono::Utc::now(),
|
|
};
|
|
|
|
user::Entity::insert(root.clone().into_active_model()).exec(db).await?;
|
|
|
|
for i in (0..100).rev() {
|
|
let oid = uuid::Uuid::new_v4();
|
|
let aid = uuid::Uuid::new_v4();
|
|
object::Entity::insert(object::ActiveModel {
|
|
id: Set(format!("{domain}/objects/{oid}")),
|
|
name: Set(None),
|
|
object_type: Set(crate::activitystream::object::ObjectType::Note),
|
|
attributed_to: Set(Some(format!("{domain}/users/root"))),
|
|
summary: Set(None),
|
|
content: Set(Some(format!("[{i}] Tic(k). Quasiparticle of intensive multiplicity. Tics (or ticks) are intrinsically several components of autonomously numbering anorganic populations, propagating by contagion between segmentary divisions in the order of nature. Ticks - as nonqualitative differentially-decomposable counting marks - each designate a multitude comprehended as a singular variation in tic(k)-density."))),
|
|
published: Set(chrono::Utc::now() - std::time::Duration::from_secs(60*i)),
|
|
}).exec(db).await?;
|
|
|
|
activity::Entity::insert(activity::ActiveModel {
|
|
id: Set(format!("{domain}/activities/{aid}")),
|
|
activity_type: Set(crate::activitystream::object::activity::ActivityType::Create),
|
|
actor: Set(format!("{domain}/users/root")),
|
|
object: Set(Some(format!("{domain}/objects/{oid}"))),
|
|
target: Set(None),
|
|
published: Set(chrono::Utc::now() - std::time::Duration::from_secs(60*i)),
|
|
to: Set(Audience(vec![PUBLIC_TARGET.to_string()])),
|
|
bto: Set(Audience::default()),
|
|
cc: Set(Audience(vec![root.followers().id().unwrap_or("").to_string()])),
|
|
bcc: Set(Audience::default()),
|
|
}).exec(db).await?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|