2024-03-21 01:09:33 +01:00
use sea_orm ::IntoActiveModel ;
use crate ::{ activitypub ::PUBLIC_TARGET , activitystream ::object ::actor ::Actor , model ::activity ::Audience } ;
2024-03-16 03:27:36 +01:00
pub mod user ;
2024-03-16 05:45:58 +01:00
pub mod object ;
2023-12-30 05:08:05 +01:00
pub mod activity ;
2024-03-16 05:45:58 +01:00
2024-03-16 20:09:06 +01:00
#[ derive(Debug, Clone, thiserror::Error) ]
#[ error( " missing required field: '{0}' " ) ]
2024-03-19 01:00:44 +01:00
pub struct FieldError ( pub & 'static str ) ;
2024-03-16 20:09:06 +01:00
2024-03-20 08:56:35 +01:00
pub async fn faker ( db : & sea_orm ::DatabaseConnection , domain : String ) -> Result < ( ) , sea_orm ::DbErr > {
2024-03-21 01:09:33 +01:00
use sea_orm ::{ EntityTrait , Set } ;
let root = user ::Model {
id : format ! ( " {domain}/users/root " ) ,
2024-03-21 03:35:07 +01:00
name : Some ( " μpub " . into ( ) ) ,
2024-03-21 01:09:33 +01:00
domain : crate ::activitypub ::domain ( & domain ) ,
2024-03-21 02:50:48 +01:00
preferred_username : " root " . to_string ( ) ,
2024-03-21 03:35:07 +01:00
summary : Some ( " hello world! i'm manually generated but served dynamically from db! check progress at https://git.alemi.dev/upub.git " . to_string ( ) ) ,
2024-03-21 01:09:33 +01:00
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 ( ) ,
2024-03-21 02:11:31 +01:00
private_key : None ,
// TODO generate a fresh one every time
public_key : " -----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA01IkF1A8t7zUS7x3ZqIx
NvG / X43JEJTdgPOFufOKMBTK48uMqrODK3wflaK6cSOMWkoOYHyWNhw10vL53GR9
iOOGUHTaU7aoV7KBb5Fbh / tN9ZyN / S6FdCfpXze93CzpKQGNJa4SZ4FAFw2Ji1JJ
pdT7r + vaa5TkYTQuIgeHFisVEQAhmlz9xPbfPRPxSskroK7OnJSLMZ + aJvJHc9uX
kOq9wKgagV / I5ka7H3rRLTG1mBC97lrSfNdXfPRF //S4mFs095s+Pbnj0Hajf+qf
1 Dryarmn6EmQi + diyhxFD3E8PWtMSBHrK + nmsiE58zjR / gd7G8SrXr4jtW + jcI6n
UQIDAQAB
- - - - - END PUBLIC KEY - - - - - " .into()
2024-03-21 01:09:33 +01:00
} ;
2024-03-16 05:45:58 +01:00
2024-03-21 01:09:33 +01:00
user ::Entity ::insert ( root . clone ( ) . into_active_model ( ) ) . exec ( db ) . await ? ;
2024-03-16 05:45:58 +01:00
2024-03-20 07:53:45 +01:00
for i in ( 0 .. 100 ) . rev ( ) {
let oid = uuid ::Uuid ::new_v4 ( ) ;
let aid = uuid ::Uuid ::new_v4 ( ) ;
object ::Entity ::insert ( object ::ActiveModel {
2024-03-21 01:09:33 +01:00
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 ) ) ,
2024-03-20 07:53:45 +01:00
} ) . exec ( db ) . await ? ;
2024-03-16 05:45:58 +01:00
2024-03-20 07:53:45 +01:00
activity ::Entity ::insert ( activity ::ActiveModel {
2024-03-21 01:09:33 +01:00
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 ( ) ) ,
2024-03-20 07:53:45 +01:00
} ) . exec ( db ) . await ? ;
}
2024-03-16 05:45:58 +01:00
Ok ( ( ) )
}