diff --git a/Cargo.lock b/Cargo.lock index 388c0fc..402385e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -335,6 +335,7 @@ dependencies = [ "rocket", "server", "sqlx", + "toml", ] [[package]] diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..89976bc --- /dev/null +++ b/config.toml @@ -0,0 +1,2 @@ +[server] +host = "https://ferri.amy.mov" \ No newline at end of file diff --git a/ferri-cli/Cargo.toml b/ferri-cli/Cargo.toml index 2d509da..b2d9f10 100644 --- a/ferri-cli/Cargo.toml +++ b/ferri-cli/Cargo.toml @@ -8,4 +8,5 @@ main = { path = "../ferri-main/" } server = { path = "../ferri-server" } rocket = { workspace = true } sqlx = { workspace = true } -clap = { version = "4", features = ["derive"] } \ No newline at end of file +clap = { version = "4", features = ["derive"] } +toml = "0.8.20" diff --git a/ferri-cli/src/main.rs b/ferri-cli/src/main.rs index f3bfda4..3d415c8 100644 --- a/ferri-cli/src/main.rs +++ b/ferri-cli/src/main.rs @@ -5,17 +5,30 @@ use sqlx::sqlite::SqlitePool; use std::env; use clap::Parser; +use main::config; +use std::fs; +use std::path::{Path, PathBuf}; #[derive(Parser)] #[command(version, about, long_about = None)] struct Cli { #[arg(short, long)] init: bool, + + #[arg(short, long)] + config: PathBuf, +} + +pub fn read_config(path: impl AsRef) -> config::Config { + let content = fs::read_to_string(path).unwrap(); + toml::from_str(&content).unwrap() } #[rocket::main] async fn main() { let cli = Cli::parse(); + let config = read_config(cli.config); + if cli.init { // Seed DB let pool = SqlitePool::connect(&env::var("DATABASE_URL").unwrap()) @@ -28,9 +41,9 @@ async fn main() { INSERT INTO actor (id, inbox, outbox) VALUES (?1, ?2, ?3) "#, - "https://ferri.amy.mov/users/c81db53f-d836-4283-a835-26606c9d14ff", - "https://ferri.amy.mov/users/c81db53f-d836-4283-a835-26606c9d14ff/inbox", - "https://ferri.amy.mov/users/c81db53f-d836-4283-a835-26606c9d14ff/outbox" + "https://ferri.amy.mov/users/9b9d497b-2731-435f-a929-e609ca69dac9", + "https://ferri.amy.mov/users/9b9d497b-2731-435f-a929-e609ca69dac9/inbox", + "https://ferri.amy.mov/users/9b9d497b-2731-435f-a929-e609ca69dac9/outbox" ) .execute(&mut *conn) .await @@ -43,13 +56,13 @@ async fn main() { "#, "9b9d497b-2731-435f-a929-e609ca69dac9", "amy", - "https://ferri.amy.mov/users/c81db53f-d836-4283-a835-26606c9d14ff", + "https://ferri.amy.mov/users/9b9d497b-2731-435f-a929-e609ca69dac9", "amy" ) .execute(&mut *conn) .await .unwrap(); } else { - let _ = launch().launch().await; + let _ = launch(config).launch().await; } } diff --git a/ferri-main/src/config/mod.rs b/ferri-main/src/config/mod.rs new file mode 100644 index 0000000..5af1eef --- /dev/null +++ b/ferri-main/src/config/mod.rs @@ -0,0 +1,11 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Debug)] +pub struct ServerConfig { + pub host: String, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Config { + pub server: ServerConfig, +} diff --git a/ferri-main/src/lib.rs b/ferri-main/src/lib.rs index 301ed9c..4d8826e 100644 --- a/ferri-main/src/lib.rs +++ b/ferri-main/src/lib.rs @@ -1 +1,2 @@ pub mod ap; +pub mod config; diff --git a/ferri-server/src/endpoints/api/user.rs b/ferri-server/src/endpoints/api/user.rs index a18a2f0..edf84f2 100644 --- a/ferri-server/src/endpoints/api/user.rs +++ b/ferri-server/src/endpoints/api/user.rs @@ -76,10 +76,7 @@ pub async fn new_follow( }; let req = ap::OutgoingActivity { - signed_by: format!( - "https://ferri.amy.mov/users/{}#main-key", - follower.username() - ), + signed_by: format!("{}#main-key", follower.uri()), req: activity, to: followed.actor().clone(), }; diff --git a/ferri-server/src/endpoints/custom.rs b/ferri-server/src/endpoints/custom.rs index 61a5aae..25dca75 100644 --- a/ferri-server/src/endpoints/custom.rs +++ b/ferri-server/src/endpoints/custom.rs @@ -36,7 +36,7 @@ pub async fn finger_account(mut db: Connection, account: &str) -> status::Ac r#" INSERT INTO user (id, username, actor_id, display_name) VALUES (?1, ?2, ?3, ?4) - ON CONFLICT(id) DO NOTHING + ON CONFLICT(actor_id) DO NOTHING "#, uuid, username, @@ -47,7 +47,7 @@ pub async fn finger_account(mut db: Connection, account: &str) -> status::Ac .await .unwrap(); - status::Accepted(format!("https://ferri.amy.mov/users/{}", username)) + status::Accepted(format!("https://ferri.amy.mov/users/{}", uuid)) } pub async fn resolve_user(acct: &str, host: &str) -> types::Person { diff --git a/ferri-server/src/lib.rs b/ferri-server/src/lib.rs index 13651ed..176de74 100644 --- a/ferri-server/src/lib.rs +++ b/ferri-server/src/lib.rs @@ -3,6 +3,7 @@ use endpoints::{ custom, inbox, oauth, user, well_known, }; use main::ap::http; +use main::config::Config; use rocket::{ Build, Request, Rocket, build, get, http::ContentType, @@ -20,7 +21,8 @@ mod types; pub struct Db(sqlx::SqlitePool); #[get("/")] -async fn user_profile() -> (ContentType, &'static str) { +async fn user_profile(cfg: &rocket::State) -> (ContentType, &'static str) { + dbg!(cfg); (ContentType::HTML, "

hello

") } @@ -58,9 +60,10 @@ impl<'a> FromRequest<'a> for AuthenticatedUser { } } -pub fn launch() -> Rocket { +pub fn launch(cfg: Config) -> Rocket { let http_client = http::HttpClient::new(); build() + .manage(cfg) .manage(http_client) .attach(Db::init()) .attach(cors::CORS)