diff --git a/core/src/lib.rs b/core/src/lib.rs new file mode 100644 index 0000000..24c4d1d --- /dev/null +++ b/core/src/lib.rs @@ -0,0 +1,41 @@ +//! # HomeDisk cloud server +//! +//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github +//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs +//! [total-lines]: https://img.shields.io/tokei/lines/github/MedzikUser/HomeDisk?style=for-the-badge&logo=github&color=fede00 +//! [code-size]: https://img.shields.io/github/languages/code-size/MedzikUser/HomeDisk?style=for-the-badge&color=c8df52&logo=github +//! [ci]: https://img.shields.io/github/workflow/status/MedzikUser/HomeDisk/Rust/main?style=for-the-badge +//! +//! [home-screenshot]: https://cdn.medzik.xyz/fz4QGfS.png +//! [login-screenshot]: https://cdn.medzik.xyz/vo10bes.png +//! +//! [![github]](https://github.com/MedzikUser/HomeDisk) +//! [![docs-rs]](https://homedisk-doc.vercel.app) +//! [![total-lines]](https://github.com/MedzikUser/HomeDisk) +//! [![code-size]](https://github.com/MedzikUser/HomeDisk) +//! [![ci]](https://github.com/MedzikUser/HomeDisk/actions/workflows/rust.yml) +//! +//! ![home-screenshot] +//! ![login-screenshot] +//! +//! ## 👨‍💻 Building +//! +//! First clone the repository: `git clone https://github.com/MedzikUser/HomeDisk.git` +//! +//! ### Requirements +//! - [Rust](https://rust-lang.org) +//! +//! To build run the command: `cargo build --release` +//! +//! The compiled binary can be found in `./target/release/homedisk` +//! +//! ## 🖴 Create an empty SQLite database from a tables template +//! +//! ### Requirements +//! - [SQLite3](https://sqlite.org) +//! +//! Run command `sqlite3 homedisk.db < tables.sql` to create SQLite database +//! +//! ## Configure +//! +//! Go to [config](../homedisk_types/config/index.html) module diff --git a/core/src/main.rs b/core/src/main.rs index 3cf1506..ede733f 100644 --- a/core/src/main.rs +++ b/core/src/main.rs @@ -2,7 +2,6 @@ use homedisk_database::Database; use homedisk_server::serve_http; use homedisk_types::config::Config; -/// Main function #[tokio::main] async fn main() -> anyhow::Result<()> { // init better_panic diff --git a/database/src/lib.rs b/database/src/lib.rs index 7c09efe..deab2c0 100644 --- a/database/src/lib.rs +++ b/database/src/lib.rs @@ -1,7 +1,5 @@ mod sqlite; -/// Imported from `homedisk_types::database::User`. pub use homedisk_types::database::User; -/// Imported from `homedisk_types::errors::DatabaseError`. pub use homedisk_types::errors::DatabaseError as Error; pub use sqlite::*; diff --git a/types/src/auth/login.rs b/types/src/auth/login.rs index 612d2ac..c18776a 100644 --- a/types/src/auth/login.rs +++ b/types/src/auth/login.rs @@ -15,6 +15,7 @@ pub struct Request { /// HTTP `/auth/login` Response #[derive(Debug, Serialize, Deserialize, Clone, Zeroize, ZeroizeOnDrop)] pub enum Response { + #[allow(missing_docs)] LoggedIn { /// User access token access_token: String, diff --git a/types/src/config/mod.rs b/types/src/config/mod.rs index d4dbbe9..6e72709 100644 --- a/types/src/config/mod.rs +++ b/types/src/config/mod.rs @@ -1,7 +1,26 @@ -//! Types for configuration file +//! # Configuration file +//! +//! Path to a config file is `config.toml` in the server root directory. +//! +//! Example config: +//! +//! ```toml +//! [http] +//! host = "0.0.0.0" # HTTP Host +//! port = 8080 # HTTP Port +//! cors = ["homedisk.medzik.xyz"] # Domains allowed for CORS +//! +//! [jwt] +//! secret = "secret key used to sign tokens" # JWT Secret string (used to sign tokens) +//! expires = 24 # Token expiration time (in hours) +//! +//! [storage] +//! path = "/home/homedisk" # # Directory where user files will be stored +//! ``` +//! +//! ## External docs +//! - [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) -#[cfg(feature = "config")] -mod toml; mod types; pub use types::*; diff --git a/types/src/config/toml.rs b/types/src/config/toml.rs deleted file mode 100644 index 8fea97c..0000000 --- a/types/src/config/toml.rs +++ /dev/null @@ -1,27 +0,0 @@ -use std::fs; - -use anyhow::Result; - -use crate::option_return; - -use super::types::Config; - -impl Config { - /// Parse configuration file - /// ```no_run - /// use homedisk_types::config::Config; - /// - /// let config = Config::parse().unwrap(); - /// ``` - pub fn parse() -> Result { - // get file path of config file - let config_dir = option_return!(dirs::config_dir(), "find config dir")?; - let config_path = format!("{}/homedisk/config.toml", config_dir.to_string_lossy()); - - // read file content to string - let config = fs::read_to_string(config_path)?; - - // parse config and return it - Ok(toml::from_str(&config)?) - } -} diff --git a/types/src/config/types.rs b/types/src/config/types.rs index 90e2326..483f85e 100644 --- a/types/src/config/types.rs +++ b/types/src/config/types.rs @@ -1,12 +1,19 @@ //! Configuration file types +use std::fs; + use serde::{Deserialize, Serialize}; +use crate::option_return; + /// Config type #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Config { + /// Configure HTTP settings pub http: ConfigHTTP, + /// Configure Json Web Token settings pub jwt: ConfigJWT, + /// Configure storage settings pub storage: ConfigStorage, } @@ -36,3 +43,24 @@ pub struct ConfigStorage { /// Directory where user files will be stored pub path: String, } + +#[cfg(feature = "config")] +impl Config { + /// Parse configuration file + /// ```no_run + /// use homedisk_types::config::Config; + /// + /// let config = Config::parse().unwrap(); + /// ``` + pub fn parse() -> anyhow::Result { + // get file path of config file + let config_dir = option_return!(dirs::config_dir(), "find config dir")?; + let config_path = format!("{}/homedisk/config.toml", config_dir.to_string_lossy()); + + // read file content to string + let config = fs::read_to_string(config_path)?; + + // parse config and return it + Ok(toml::from_str(&config)?) + } +} diff --git a/types/src/fs/list.rs b/types/src/fs/list.rs index 1597186..ef5cf41 100644 --- a/types/src/fs/list.rs +++ b/types/src/fs/list.rs @@ -5,13 +5,16 @@ use serde::{Deserialize, Serialize}; /// HTTP `/fs/list` Request #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Request { + /// Path to directory pub path: String, } /// HTTP `/fs/list` Response #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Response { + /// Vector with files info pub files: Vec, + /// Vector with directories info pub dirs: Vec, }