diff --git a/config.sample.toml b/config.sample.toml index dab595176e188fe39bf872a2fb52c3d7251d42e9..d0114eb0066e71e3d6f850de1fca00ec616c2ecd 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 1323cb0f1498eac6eb751349ca8e2180c1c8252b..e88156931c8963d5445a5b0f68b2ea6b304fc767 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 f3a07b4cb6379d316689e52890f20d01990f35b3..dcf7ec4aa94039f622dfebf73cd621492a76643d 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 8446a956dfeab56637877f9f39c1f923306bcb52..922360d9dba3a1d5f3db4b3ca03b9788f1aad435 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 e9a2c9bd8ea5702e5625ce045eb1224403f8f150..701d26a164b99e530843d7056218ecb3c8daca30 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 76487fd6b9cdbaee1730cf510fd82a1cc8812b4f..73955f951c0282b152db3f2d36520ab67251e253 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(); }