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