From 9bc640aadcd2c02374fa195aed09452b4a3bb3ea Mon Sep 17 00:00:00 2001 From: aprilthepink Date: Tue, 9 Apr 2024 19:55:07 +0200 Subject: [PATCH] [fix] format files --- build.rs | 10 ++++---- flake.lock | 41 ++++++++++++++++++------------- flake.nix | 9 ++++++- shell.nix | 2 +- src/activities/create_post.rs | 2 +- src/activities/mod.rs | 2 +- src/database.rs | 2 +- src/http.rs | 2 +- src/main.rs | 45 +++++++++++++++++++++++++---------- src/objects/mod.rs | 2 +- src/objects/post.rs | 7 ++---- 11 files changed, 78 insertions(+), 46 deletions(-) diff --git a/build.rs b/build.rs index eedc3cd..5d67e88 100644 --- a/build.rs +++ b/build.rs @@ -1,11 +1,11 @@ #[cfg(target_os = "windows")] fn main() { vcpkg::Config::new() - .emit_includes(true) - .copy_dlls(true) - .find_package("libpq").unwrap(); + .emit_includes(true) + .copy_dlls(true) + .find_package("libpq") + .unwrap(); } #[cfg(not(target_os = "windows"))] -fn main() { -} \ No newline at end of file +fn main() {} diff --git a/flake.lock b/flake.lock index 8dd6949..450c78c 100644 --- a/flake.lock +++ b/flake.lock @@ -18,6 +18,26 @@ "type": "github" } }, + "nix-github-actions": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1703863825, + "narHash": "sha256-rXwqjtwiGKJheXB43ybM8NwWB8rO2dSRrEqes0S7F5Y=", + "owner": "nix-community", + "repo": "nix-github-actions", + "rev": "5163432afc817cf8bd1f031418d1869e4c9d5547", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nix-github-actions", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1710806803, @@ -52,25 +72,10 @@ "type": "github" } }, - "nixpkgs_2": { - "locked": { - "lastModified": 1708475490, - "narHash": "sha256-g1v0TsWBQPX97ziznfJdWhgMyMGtoBFs102xSYO4syU=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "0e74ca98a74bc7270d28838369593635a5db3260", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, "root": { "inputs": { "flake-parts": "flake-parts", + "nix-github-actions": "nix-github-actions", "nixpkgs": "nixpkgs", "systems": "systems", "treefmt-nix": "treefmt-nix" @@ -93,7 +98,9 @@ }, "treefmt-nix": { "inputs": { - "nixpkgs": "nixpkgs_2" + "nixpkgs": [ + "nixpkgs" + ] }, "locked": { "lastModified": 1710781103, diff --git a/flake.nix b/flake.nix index 3e43a27..f8c9ec4 100644 --- a/flake.nix +++ b/flake.nix @@ -1,12 +1,19 @@ - { inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + flake-parts.inputs.nixpkgs.follows = "nixpkgs"; + systems.url = "github:nix-systems/default"; + systems.inputs.nixpkgs.follows = "nixpkgs"; + + nix-github-actions.url = "github:nix-community/nix-github-actions"; + nix-github-actions.inputs.nixpkgs.follows = "nixpkgs"; # Dev tools treefmt-nix.url = "github:numtide/treefmt-nix"; + treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = inputs: diff --git a/shell.nix b/shell.nix index 60f783b..63102f8 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,4 @@ -{ pkgs ? import {}}: +{ pkgs ? import { } }: pkgs.mkShell { buildInputs = with pkgs; [ diff --git a/src/activities/create_post.rs b/src/activities/create_post.rs index d4764f0..74fd388 100644 --- a/src/activities/create_post.rs +++ b/src/activities/create_post.rs @@ -1,9 +1,9 @@ use crate::{ database::DatabaseHandle, error::Error, + objects::post::DbPost, objects::{person::DbUser, post::Note}, utils::generate_object_id, - objects::post::DbPost, }; use activitypub_federation::{ activity_sending::SendActivityTask, diff --git a/src/activities/mod.rs b/src/activities/mod.rs index 8cb9102..7e15ee0 100644 --- a/src/activities/mod.rs +++ b/src/activities/mod.rs @@ -1 +1 @@ -pub mod create_post; \ No newline at end of file +pub mod create_post; diff --git a/src/database.rs b/src/database.rs index 60e10ac..7b6c7fa 100644 --- a/src/database.rs +++ b/src/database.rs @@ -1,4 +1,4 @@ -use crate::{objects::person::DbUser, error::Error}; +use crate::{error::Error, objects::person::DbUser}; use anyhow::anyhow; use std::sync::{Arc, Mutex}; diff --git a/src/http.rs b/src/http.rs index d8bca76..cd724ee 100644 --- a/src/http.rs +++ b/src/http.rs @@ -1,6 +1,6 @@ use crate::{ - error::Error, database::DatabaseHandle, + error::Error, objects::person::{DbUser, PersonAcceptedActivities}, }; use activitypub_federation::{ diff --git a/src/main.rs b/src/main.rs index 5f0af37..d5aa981 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,17 +6,20 @@ use database::Database; use http::{http_get_user, http_post_user_inbox, webfinger}; use objects::person::DbUser; use serde::{Deserialize, Serialize}; -use tokio::signal; use std::{ - collections::HashMap, env, net::ToSocketAddrs, sync::{Arc, Mutex} + collections::HashMap, + env, + net::ToSocketAddrs, + sync::{Arc, Mutex}, }; +use tokio::signal; -mod database; -mod objects; mod activities; -mod utils; +mod database; mod error; mod http; +mod objects; +mod utils; #[derive(Debug, Clone)] struct State { @@ -55,7 +58,15 @@ async fn main() -> actix_web::Result<(), anyhow::Error> { let server_url = env::var("LISTEN").unwrap_or("127.0.0.1:8080".to_string()); - let local_user = DbUser::new(env::var("FEDERATED_DOMAIN").unwrap_or(DOMAIN.to_string()).as_str(), env::var("LOCAL_USER_NAME").unwrap_or(LOCAL_USER_NAME.to_string()).as_str()).unwrap(); + let local_user = DbUser::new( + env::var("FEDERATED_DOMAIN") + .unwrap_or(DOMAIN.to_string()) + .as_str(), + env::var("LOCAL_USER_NAME") + .unwrap_or(LOCAL_USER_NAME.to_string()) + .as_str(), + ) + .unwrap(); let database = Arc::new(Database { users: Mutex::new(vec![local_user]), @@ -66,12 +77,22 @@ async fn main() -> actix_web::Result<(), anyhow::Error> { let data = FederationConfig::builder() .domain(env::var("FEDERATED_DOMAIN").expect("FEDERATED_DOMAIN must be set")) .app_data(state.clone().database) - .build().await?; - + .build() + .await?; let mut labels = HashMap::new(); - labels.insert("domain".to_string(), env::var("FEDERATED_DOMAIN").expect("FEDERATED_DOMAIN must be set").to_string()); - labels.insert("name".to_string(), env::var("LOCAL_USER_NAME").expect("LOCAL_USER_NAME must be set").to_string()); + labels.insert( + "domain".to_string(), + env::var("FEDERATED_DOMAIN") + .expect("FEDERATED_DOMAIN must be set") + .to_string(), + ); + labels.insert( + "name".to_string(), + env::var("LOCAL_USER_NAME") + .expect("LOCAL_USER_NAME must be set") + .to_string(), + ); let prometheus = PrometheusMetricsBuilder::new("api") .endpoint("/metrics") @@ -99,11 +120,11 @@ async fn main() -> actix_web::Result<(), anyhow::Error> { tokio::spawn(http_server); match signal::ctrl_c().await { - Ok(()) => {}, + Ok(()) => {} Err(err) => { eprintln!("Unable to listen for shutdown signal: {}", err); // we also shut down in case of error - }, + } } Ok(()) diff --git a/src/objects/mod.rs b/src/objects/mod.rs index 12b5bfd..b5239ab 100644 --- a/src/objects/mod.rs +++ b/src/objects/mod.rs @@ -1,2 +1,2 @@ pub mod person; -pub mod post; \ No newline at end of file +pub mod post; diff --git a/src/objects/post.rs b/src/objects/post.rs index 99bdd28..e49e78b 100644 --- a/src/objects/post.rs +++ b/src/objects/post.rs @@ -1,9 +1,6 @@ use crate::{ - activities::create_post::CreatePost, - database::DatabaseHandle, - error::Error, - utils::generate_object_id, - objects::person::DbUser, + activities::create_post::CreatePost, database::DatabaseHandle, error::Error, + objects::person::DbUser, utils::generate_object_id, }; use activitypub_federation::{ config::Data,