mirror of
https://github.com/MedzikUser/HomeDisk.git
synced 2024-08-14 21:46:53 +00:00
doc: update
This commit is contained in:
parent
d72becdb88
commit
f9b46c34db
8 changed files with 95 additions and 33 deletions
41
core/src/lib.rs
Normal file
41
core/src/lib.rs
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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::*;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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::*;
|
||||
|
|
|
@ -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<Config> {
|
||||
// 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)?)
|
||||
}
|
||||
}
|
|
@ -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<Config> {
|
||||
// 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)?)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<FileInfo>,
|
||||
/// Vector with directories info
|
||||
pub dirs: Vec<DirInfo>,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue