From c5e333a9ebd99554cc83cfa7c66e56a48ad00613 Mon Sep 17 00:00:00 2001 From: Volkor <me@volkor.me> Date: Mon, 16 Dec 2024 03:45:29 +1100 Subject: [PATCH] run cargo fmt --- config.sample.toml | 2 +- src/config.rs | 22 ++++++++++++++++++---- src/handlers/admin.rs | 3 ++- src/handlers/delete_file.rs | 9 +++++---- src/handlers/user_profile.rs | 6 ++++-- src/main.rs | 7 +++++-- 6 files changed, 35 insertions(+), 14 deletions(-) diff --git a/config.sample.toml b/config.sample.toml index dab5951..d0114eb 100644 --- a/config.sample.toml +++ b/config.sample.toml @@ -17,7 +17,7 @@ sql_backend = "sqlite" # https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING # url = "postgres://ephemeral:changeme@localhost:5432/ephemeral" -url = "sqlite://data/ephemeral.db" +url = "sqlite://ephemeral.db" [logging] diff --git a/src/config.rs b/src/config.rs index 1323cb0..e881569 100644 --- a/src/config.rs +++ b/src/config.rs @@ -71,7 +71,8 @@ impl Default for DatabaseConfig { impl Default for LoggingConfig { fn default() -> Self { LoggingConfig { - level: "ephemeral=info,sqlx=error,hyper=error,salvo_extra=error,salvo=error,mio=error".to_string(), + level: "ephemeral=info,sqlx=error,hyper=error,salvo_extra=error,salvo=error,mio=error" + .to_string(), metrics: true, } } @@ -88,8 +89,21 @@ impl Default for OperationsConfig { file_expiry_min: 604800, file_expiry_max: 31536000, max_filesize: 1073741824, // 10 MB - banned_mimetype: vec!["application/x-msdownload".to_string(), "application/x-msi".to_string(), "application/x-silverlight".to_string(), "application/x-ms-dos-executable".to_string(), "application/vnd.microsoft.portable-executable".to_string()], - unsafe_mimetype: vec!["text/html".to_string(), "text/javascript".to_string(), "application/javascript".to_string(), "text/css".to_string(), "application/x-httpd-php".to_string(), "application/xhtml+xml".to_string()], + banned_mimetype: vec![ + "application/x-msdownload".to_string(), + "application/x-msi".to_string(), + "application/x-silverlight".to_string(), + "application/x-ms-dos-executable".to_string(), + "application/vnd.microsoft.portable-executable".to_string(), + ], + unsafe_mimetype: vec![ + "text/html".to_string(), + "text/javascript".to_string(), + "application/javascript".to_string(), + "text/css".to_string(), + "application/x-httpd-php".to_string(), + "application/xhtml+xml".to_string(), + ], } } } @@ -102,4 +116,4 @@ impl Default for UploadConfig { fallback_key: "set-me".to_string(), } } -} \ No newline at end of file +} diff --git a/src/handlers/admin.rs b/src/handlers/admin.rs index f3a07b4..dcf7ec4 100644 --- a/src/handlers/admin.rs +++ b/src/handlers/admin.rs @@ -174,7 +174,8 @@ fn generate_html_tree(tree: &[TreeNode]) -> String { fn generate_html(node: &TreeNode) -> String { // Humanize the time. let key_creation = { - let datetime: DateTime<Utc> = DateTime::from_timestamp(node.key.creation_time.into(), 0).unwrap(); + let datetime: DateTime<Utc> = + DateTime::from_timestamp(node.key.creation_time.into(), 0).unwrap(); let human_time = HumanTime::from(datetime); human_time.to_text_en(Accuracy::Rough, Tense::Past) }; diff --git a/src/handlers/delete_file.rs b/src/handlers/delete_file.rs index 8446a95..922360d 100644 --- a/src/handlers/delete_file.rs +++ b/src/handlers/delete_file.rs @@ -33,12 +33,13 @@ pub async fn delete_file(req: &mut Request, res: &mut Response, depot: &mut Depo // Grab the file's owner key from the db. let owner = db::check_owner(sqlconn, filename).await; - debug!("Deletion attempt: user: {} file owner: {:?}", client_key.uuid, owner); + debug!( + "Deletion attempt: user: {} file owner: {:?}", + client_key.uuid, owner + ); // Compare the client_key and owner. let authorized = match owner { - Ok(owner_key) => { - client_key.uuid == owner_key - } + Ok(owner_key) => client_key.uuid == owner_key, Err(_) => false, }; debug!("authorized: {}", authorized); diff --git a/src/handlers/user_profile.rs b/src/handlers/user_profile.rs index e9a2c9b..701d26a 100644 --- a/src/handlers/user_profile.rs +++ b/src/handlers/user_profile.rs @@ -42,7 +42,8 @@ pub async fn user_profile(req: &mut Request, res: &mut Response, depot: &mut Dep // Humanise the creation date of the API Key. let key_creation = { - let datetime: DateTime<Utc> = DateTime::from_timestamp(client_key.creation_time.into(), 0).unwrap(); + let datetime: DateTime<Utc> = + DateTime::from_timestamp(client_key.creation_time.into(), 0).unwrap(); let human_time = HumanTime::from(datetime); human_time.to_text_en(Accuracy::Rough, Tense::Present) }; @@ -158,7 +159,8 @@ pub async fn user_profile(req: &mut Request, res: &mut Response, depot: &mut Dep Ok(key) => { // Humanise the creation_time let human_creation_time = { - let datetime: DateTime<Utc> = DateTime::from_timestamp(key.creation_time.into(), 0).unwrap(); + let datetime: DateTime<Utc> = + DateTime::from_timestamp(key.creation_time.into(), 0).unwrap(); let human_time = HumanTime::from(datetime); human_time.to_text_en(Accuracy::Rough, Tense::Past) }; diff --git a/src/main.rs b/src/main.rs index 76487fd..73955f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,7 @@ -use figment::{Figment, providers::{Format, Toml, Env}}; +use figment::{ + providers::{Env, Format, Toml}, + Figment, +}; use magic::Cookie; use once_cell::sync::OnceCell; use salvo::prelude::*; @@ -74,7 +77,7 @@ async fn main() { Some(DatabaseType::Sqlite) => { info!("DB: Using SQLite backend `{}`", &db_url); // TODO: Check if DB Exists, if not, create. - + let pool = SqlitePool::connect(db_url).await.unwrap(); SQLITE.set(pool).unwrap(); } -- GitLab