chore: some changes

This commit is contained in:
MedzikUser 2022-08-29 13:12:16 +02:00
parent b5ff8dd32c
commit dc8ccff079
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
4 changed files with 6 additions and 25 deletions

View File

@ -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"

View File

@ -13,7 +13,7 @@ pub const DATABASE_FILE: &str = "homedisk.db";
async fn main() {
logger::init();
let config = Config::parse().expect("parse config");
let config = Config::parse().expect("Failed to parse configuration file");
// open database connection
let db =
@ -23,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
@ -60,7 +59,6 @@ async fn main() {
port = config.http.port
);
// start http server
serve_http(host, origins, db, config)
.await
.expect("start http server");

View File

@ -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))
}
}

View File

@ -2,7 +2,6 @@
pub mod auth;
pub mod config;
pub mod custom_option;
#[cfg(feature = "database")]
pub mod database;
pub mod errors;