mirror of
https://github.com/versia-pub/activitypub.git
synced 2025-12-06 06:38:20 +01:00
fomat
This commit is contained in:
parent
4d4e3ed794
commit
fa3e4634cb
|
|
@ -8,8 +8,9 @@ pub struct Migration;
|
|||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
|
||||
manager.drop_table(Table::drop().table(Post::Table).to_owned()).await?;
|
||||
manager
|
||||
.drop_table(Table::drop().table(Post::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,12 @@
|
|||
use crate::{
|
||||
database::StateHandle, entities::{post, user}, error::Error, objects::{person::DbUser, post::{DbPost, Note}}, utils::generate_object_id
|
||||
database::StateHandle,
|
||||
entities::{post, user},
|
||||
error::Error,
|
||||
objects::{
|
||||
person::DbUser,
|
||||
post::{DbPost, Note},
|
||||
},
|
||||
utils::generate_object_id,
|
||||
};
|
||||
use activitypub_federation::{
|
||||
activity_sending::SendActivityTask,
|
||||
|
|
@ -35,8 +42,12 @@ impl CreatePost {
|
|||
id: generate_object_id(data.domain())?,
|
||||
};
|
||||
let create_with_context = WithContext::new_default(create);
|
||||
let sends =
|
||||
SendActivityTask::prepare(&create_with_context, &data.local_user().await?, vec![inbox], data)
|
||||
let sends = SendActivityTask::prepare(
|
||||
&create_with_context,
|
||||
&data.local_user().await?,
|
||||
vec![inbox],
|
||||
data,
|
||||
)
|
||||
.await?;
|
||||
for send in sends {
|
||||
send.sign_and_send(data).await?;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use super::entities::prelude::User;
|
||||
use crate::{entities::user, error::Error, objects::person::DbUser};
|
||||
use anyhow::anyhow;
|
||||
use sea_orm::{DatabaseConnection, EntityTrait};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use super::entities::prelude::User;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {}
|
||||
|
|
@ -24,7 +24,10 @@ pub struct Database {
|
|||
|
||||
impl State {
|
||||
pub async fn local_user(&self) -> Result<user::Model, Error> {
|
||||
let user = User::find().one(self.database_connection.as_ref()).await?.unwrap();
|
||||
let user = User::find()
|
||||
.one(self.database_connection.as_ref())
|
||||
.await?
|
||||
.unwrap();
|
||||
Ok(user.clone())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
use crate::{
|
||||
database::StateHandle, entities::user, error::Error, objects::person::{DbUser, PersonAcceptedActivities}
|
||||
database::StateHandle,
|
||||
entities::user,
|
||||
error::Error,
|
||||
objects::person::{DbUser, PersonAcceptedActivities},
|
||||
};
|
||||
use activitypub_federation::{
|
||||
actix_web::{inbox::receive_activity, signing_actor},
|
||||
|
|
|
|||
33
src/main.rs
33
src/main.rs
|
|
@ -1,11 +1,15 @@
|
|||
use activitypub_federation::config::{FederationConfig, FederationMiddleware};
|
||||
use activitypub_federation::{
|
||||
config::{FederationConfig, FederationMiddleware},
|
||||
http_signatures::generate_actor_keypair,
|
||||
};
|
||||
use actix_web::{get, http::KeepAlive, middleware, web, App, Error, HttpResponse, HttpServer};
|
||||
use actix_web_prom::PrometheusMetricsBuilder;
|
||||
use chrono::{DateTime, Utc};
|
||||
use clap::Parser;
|
||||
use database::Database;
|
||||
use http::{http_get_user, http_post_user_inbox, webfinger};
|
||||
use objects::person::DbUser;
|
||||
use sea_orm::DatabaseConnection;
|
||||
use sea_orm::{ActiveModelTrait, DatabaseConnection, Set};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
|
|
@ -15,12 +19,13 @@ use std::{
|
|||
};
|
||||
use tokio::signal;
|
||||
use tracing::info;
|
||||
use url::Url;
|
||||
|
||||
use crate::database::{Config, State};
|
||||
|
||||
mod entities;
|
||||
mod activities;
|
||||
mod database;
|
||||
mod entities;
|
||||
mod error;
|
||||
mod http;
|
||||
mod objects;
|
||||
|
|
@ -69,12 +74,28 @@ async fn main() -> actix_web::Result<(), anyhow::Error> {
|
|||
)
|
||||
.unwrap();
|
||||
|
||||
let new_database = Arc::new(Database {
|
||||
users: Mutex::new(vec![local_user]),
|
||||
});
|
||||
let username = env::var("LOCAL_USER_NAME").unwrap_or(LOCAL_USER_NAME.to_string());
|
||||
let domain = env::var("FEDERATED_DOMAIN").unwrap_or(DOMAIN.to_string());
|
||||
|
||||
let ap_id = Url::parse(&format!("https://{}/{}", domain, &username))?;
|
||||
let inbox = Url::parse(&format!("https://{}/{}/inbox", domain, &username))?;
|
||||
let keypair = generate_actor_keypair()?;
|
||||
|
||||
let user = entities::user::ActiveModel {
|
||||
id: Set(ap_id.into()),
|
||||
username: Set(username),
|
||||
inbox: Set(inbox.to_string()),
|
||||
public_key: Set(keypair.public_key.clone()),
|
||||
private_key: Set(Some(keypair.private_key.clone())),
|
||||
last_refreshed_at: Set(chrono::offset::Utc::now()),
|
||||
local: Set(true),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let db = sea_orm::Database::connect(database_url).await?;
|
||||
|
||||
let user = user.insert(&db).await;
|
||||
|
||||
let config = Config {};
|
||||
|
||||
let state: State = State {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
use crate::{activities::create_post::CreatePost, database::{State, StateHandle}, entities::{self, user}, error::Error};
|
||||
use crate::{
|
||||
activities::create_post::CreatePost,
|
||||
database::{State, StateHandle},
|
||||
entities::{self, user},
|
||||
error::Error,
|
||||
};
|
||||
use activitypub_federation::{
|
||||
config::Data,
|
||||
fetch::object_id::ObjectId,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
use crate::{
|
||||
activities::create_post::CreatePost, database::StateHandle, entities::{post, user}, error::Error, objects::person::DbUser, utils::generate_object_id
|
||||
activities::create_post::CreatePost,
|
||||
database::StateHandle,
|
||||
entities::{post, user},
|
||||
error::Error,
|
||||
objects::person::DbUser,
|
||||
utils::generate_object_id,
|
||||
};
|
||||
use activitypub_federation::{
|
||||
config::Data,
|
||||
|
|
@ -81,7 +86,8 @@ impl Object for post::Model {
|
|||
local: Set(false),
|
||||
..Default::default()
|
||||
};
|
||||
let post = post.insert(data.app_data().database_connection.clone().as_ref())
|
||||
let post = post
|
||||
.insert(data.app_data().database_connection.clone().as_ref())
|
||||
.await?;
|
||||
|
||||
let mention = Mention {
|
||||
|
|
|
|||
Loading…
Reference in a new issue