Compare commits
2 Commits
07a9eddede
...
dc8ccff079
Author | SHA1 | Date |
---|---|---|
MedzikUser | dc8ccff079 | |
MedzikUser | b5ff8dd32c |
|
@ -1,4 +1,3 @@
|
|||
# HTTP Server
|
||||
[http]
|
||||
# HTTP host
|
||||
host = "0.0.0.0"
|
||||
|
@ -10,14 +9,12 @@ cors = [
|
|||
"localhost:8000",
|
||||
]
|
||||
|
||||
# Json Web Token
|
||||
[jwt]
|
||||
# JWT Secret string (used to sign tokens)
|
||||
secret = "secret key used to sign tokens"
|
||||
# Token expiration time in hours
|
||||
expires = 24
|
||||
expires = 24 # one day
|
||||
|
||||
# Storage
|
||||
[storage]
|
||||
# Directory where user files will be stored
|
||||
path = "/home/homedisk"
|
||||
|
|
|
@ -11,11 +11,9 @@ pub const DATABASE_FILE: &str = "homedisk.db";
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// initialize logger
|
||||
logger::init();
|
||||
|
||||
// parse config
|
||||
let config = Config::parse().expect("parse config");
|
||||
let config = Config::parse().expect("Failed to parse configuration file");
|
||||
|
||||
// open database connection
|
||||
let db =
|
||||
|
@ -25,26 +23,25 @@ async fn main() {
|
|||
info!("Creating database file...");
|
||||
|
||||
// create an empty database file
|
||||
File::create(DATABASE_FILE).expect("create a database file");
|
||||
File::create(DATABASE_FILE).expect("Failed to create a database file");
|
||||
|
||||
// open database file
|
||||
let db = Database::open(DATABASE_FILE)
|
||||
.await
|
||||
.expect("open database file");
|
||||
.expect("Failed to open database file");
|
||||
|
||||
// create tables in the database
|
||||
db.create_tables()
|
||||
.await
|
||||
.expect("create tables in the database");
|
||||
.expect("Failed to create tables in the database");
|
||||
|
||||
db
|
||||
}
|
||||
// if database file exists
|
||||
else {
|
||||
// open database connection
|
||||
Database::open(DATABASE_FILE)
|
||||
.await
|
||||
.expect("open database file")
|
||||
.expect("Failed to open database file")
|
||||
};
|
||||
|
||||
// change the type from Vec<String> to Vec<HeaderValue> so that the http server can correctly detect CORS hosts
|
||||
|
@ -62,7 +59,6 @@ async fn main() {
|
|||
port = config.http.port
|
||||
);
|
||||
|
||||
// start http server
|
||||
serve_http(host, origins, db, config)
|
||||
.await
|
||||
.expect("start http server");
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! # Configuration file
|
||||
//!
|
||||
//! Path to a config file is `config.toml` in the system configuration directory (`~/.config/homedisk/config.toml`).
|
||||
//! Path to a config file is `config.toml` in the work directory.
|
||||
//!
|
||||
//! ## Example config
|
||||
//!
|
||||
|
|
|
@ -45,16 +45,11 @@ impl Config {
|
|||
///
|
||||
/// let config = Config::parse().unwrap();
|
||||
/// ```
|
||||
pub fn parse() -> anyhow::Result<Config> {
|
||||
// get path to the user's config directory
|
||||
let sys_config_dir = dirs::config_dir().unwrap();
|
||||
// path to the homedisk config file
|
||||
let config_path = format!("{}/homedisk/config.toml", sys_config_dir.to_string_lossy());
|
||||
pub fn parse() -> anyhow::Result<Self> {
|
||||
let config_str = fs::read_to_string("config.toml")?;
|
||||
|
||||
// read file content to string
|
||||
let config = fs::read_to_string(config_path)?;
|
||||
let config = toml::from_str(&config_str)?;
|
||||
|
||||
// parse config and return it
|
||||
Ok(toml::from_str(&config)?)
|
||||
Ok(config)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
use std::io;
|
||||
|
||||
/// Custom functions implemented for Option<T>
|
||||
pub trait OptionOkOrErr<T> {
|
||||
/// If the value is some return it, if not return Error
|
||||
fn ok_or_err(self, desc: &str) -> Result<T, io::Error>;
|
||||
}
|
||||
|
||||
impl<T> OptionOkOrErr<T> for Option<T> {
|
||||
fn ok_or_err(self, desc: &str) -> Result<T, io::Error> {
|
||||
self.ok_or_else(|| io::Error::new(io::ErrorKind::Other, desc))
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
pub mod auth;
|
||||
pub mod config;
|
||||
pub mod custom_option;
|
||||
#[cfg(feature = "database")]
|
||||
pub mod database;
|
||||
pub mod errors;
|
||||
|
|
Loading…
Reference in New Issue