-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat!: use clap * fix(commands): optional * chore(main): remove pub Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * chore(run): use question mark --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
85204a0
commit e534c87
Showing
4 changed files
with
100 additions
and
67 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use std::{env, ops::Deref, path::Path}; | ||
|
||
use activitypub_federation::config::FederationConfig; | ||
use hatsu_apub::actors::ApubUser; | ||
use hatsu_db_migration::{Migrator, MigratorTrait}; | ||
use hatsu_db_schema::prelude::User; | ||
use hatsu_utils::{AppData, AppEnv, AppError}; | ||
use sea_orm::{ActiveModelTrait, Database, EntityTrait, IntoActiveModel}; | ||
|
||
pub async fn run() -> Result<(), AppError> { | ||
hatsu_tracing::init()?; | ||
|
||
tracing::info!("{}", AppEnv::info()); | ||
|
||
tracing::info!("loading environment variables"); | ||
if dotenvy::dotenv().is_err() { | ||
let env_file = | ||
env::var("HATSU_ENV_FILE").unwrap_or_else(|_| String::from("/etc/hatsu/.dev")); | ||
if dotenvy::from_path(Path::new(&env_file)).is_err() { | ||
tracing::debug!("no .env file found"); | ||
} | ||
} | ||
|
||
let env = AppEnv::init()?; | ||
|
||
tracing::info!("connecting database: {}", &env.hatsu_database_url); | ||
let conn = Database::connect(&env.hatsu_database_url).await?; | ||
|
||
tracing::info!("running database migration"); | ||
Migrator::up(&conn, None).await?; | ||
|
||
tracing::info!("checking primary account: {}", &env.hatsu_primary_account); | ||
let primary_account: ApubUser = match User::find_by_id( | ||
hatsu_utils::url::generate_user_url(&env.hatsu_domain, &env.hatsu_primary_account)? | ||
.to_string(), | ||
) | ||
.one(&conn) | ||
.await? | ||
{ | ||
Some(db_user) => db_user.into(), | ||
None => ApubUser::new(&env.hatsu_domain, &env.hatsu_primary_account) | ||
.await? | ||
.deref() | ||
.clone() | ||
.into_active_model() | ||
.insert(&conn) | ||
.await? | ||
.into(), | ||
}; | ||
|
||
let data = AppData { | ||
conn, | ||
env: env.clone(), | ||
}; | ||
|
||
tracing::info!("setup federation config"); | ||
let federation_config = FederationConfig::builder() | ||
.domain(&env.hatsu_domain) | ||
.signed_fetch_actor(&primary_account) | ||
.app_data(data) | ||
// TODO: | ||
// Disable this configuration when Pleroma supports HTTP Signature draft-11 | ||
// 当 Pleroma 支持 HTTP Signature draft-11 时,禁用此配置 | ||
// https://git.pleroma.social/pleroma/pleroma/-/issues/2939 | ||
.http_signature_compat(true) | ||
.build() | ||
.await?; | ||
|
||
tracing::info!("starting backend"); | ||
hatsu_backend::run(federation_config).await | ||
} |