mirror of
https://github.com/MedzikUser/HomeDisk.git
synced 2024-08-14 21:46:53 +00:00
chore: some changes
This commit is contained in:
parent
b5ff8dd32c
commit
dc8ccff079
4 changed files with 6 additions and 25 deletions
|
@ -1,4 +1,3 @@
|
||||||
# HTTP Server
|
|
||||||
[http]
|
[http]
|
||||||
# HTTP host
|
# HTTP host
|
||||||
host = "0.0.0.0"
|
host = "0.0.0.0"
|
||||||
|
@ -10,14 +9,12 @@ cors = [
|
||||||
"localhost:8000",
|
"localhost:8000",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Json Web Token
|
|
||||||
[jwt]
|
[jwt]
|
||||||
# JWT Secret string (used to sign tokens)
|
# JWT Secret string (used to sign tokens)
|
||||||
secret = "secret key used to sign tokens"
|
secret = "secret key used to sign tokens"
|
||||||
# Token expiration time in hours
|
# Token expiration time in hours
|
||||||
expires = 24
|
expires = 24 # one day
|
||||||
|
|
||||||
# Storage
|
|
||||||
[storage]
|
[storage]
|
||||||
# Directory where user files will be stored
|
# Directory where user files will be stored
|
||||||
path = "/home/homedisk"
|
path = "/home/homedisk"
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub const DATABASE_FILE: &str = "homedisk.db";
|
||||||
async fn main() {
|
async fn main() {
|
||||||
logger::init();
|
logger::init();
|
||||||
|
|
||||||
let config = Config::parse().expect("parse config");
|
let config = Config::parse().expect("Failed to parse configuration file");
|
||||||
|
|
||||||
// open database connection
|
// open database connection
|
||||||
let db =
|
let db =
|
||||||
|
@ -23,26 +23,25 @@ async fn main() {
|
||||||
info!("Creating database file...");
|
info!("Creating database file...");
|
||||||
|
|
||||||
// create an empty 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
|
// open database file
|
||||||
let db = Database::open(DATABASE_FILE)
|
let db = Database::open(DATABASE_FILE)
|
||||||
.await
|
.await
|
||||||
.expect("open database file");
|
.expect("Failed to open database file");
|
||||||
|
|
||||||
// create tables in the database
|
// create tables in the database
|
||||||
db.create_tables()
|
db.create_tables()
|
||||||
.await
|
.await
|
||||||
.expect("create tables in the database");
|
.expect("Failed to create tables in the database");
|
||||||
|
|
||||||
db
|
db
|
||||||
}
|
}
|
||||||
// if database file exists
|
// if database file exists
|
||||||
else {
|
else {
|
||||||
// open database connection
|
|
||||||
Database::open(DATABASE_FILE)
|
Database::open(DATABASE_FILE)
|
||||||
.await
|
.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
|
// 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
|
port = config.http.port
|
||||||
);
|
);
|
||||||
|
|
||||||
// start http server
|
|
||||||
serve_http(host, origins, db, config)
|
serve_http(host, origins, db, config)
|
||||||
.await
|
.await
|
||||||
.expect("start http server");
|
.expect("start http server");
|
||||||
|
|
|
@ -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 auth;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod custom_option;
|
|
||||||
#[cfg(feature = "database")]
|
#[cfg(feature = "database")]
|
||||||
pub mod database;
|
pub mod database;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
|
|
Loading…
Reference in a new issue