diff --git a/api/src/db.rs b/api/src/db.rs index 3b81037..1bac8af 100644 --- a/api/src/db.rs +++ b/api/src/db.rs @@ -4,13 +4,18 @@ // WARN: at the moment there are no guarantees as far as data integrity is // concerned. This means there are no real transactions +use std::env; use std::fs::OpenOptions; -use std::io::prelude::Write; use std::io::{BufWriter, BufReader}; use std::path::PathBuf; use std::collections::HashMap; use rocket::serde::{Serialize, Deserialize}; +lazy_static! { + pub static ref DB_PATH: String = { + env::var("DB_PATH").unwrap_or("keys.db".into()) + }; +} #[derive(Debug, Serialize, Deserialize)] pub struct Database { @@ -83,7 +88,6 @@ impl Database { #[cfg(test)] mod db_tests { use super::Database; - use rocket::tokio; const DB: &'static str = "new.db"; diff --git a/api/src/main.rs b/api/src/main.rs index 726e9f7..cff6f78 100644 --- a/api/src/main.rs +++ b/api/src/main.rs @@ -9,7 +9,6 @@ mod category; mod video; mod thumbnail; mod common; -mod partial; #[cfg(feature = "admin")] mod admin; diff --git a/api/src/partial.rs b/api/src/partial.rs deleted file mode 100644 index fc67e83..0000000 --- a/api/src/partial.rs +++ /dev/null @@ -1,65 +0,0 @@ -use rocket::http::Status; -use rocket::request::{Outcome, Request, FromRequest}; - -// Only single byte ranges are supported right now -pub struct Range { - start: u32, - end: Option -} - -#[derive(Debug)] -pub enum RangeError { - Invalid, - Malformed -} - - -#[rocket::async_trait] -impl<'r> FromRequest<'r> for Range { - type Error = RangeError; - async fn from_request(req: &'r Request<'_>) -> Outcome { - // No range basically just means get the whole file - let range_raw = req.headers().get_one("range"); - if range_raw.is_none() { - return Outcome::Success(Self { start: 0, end: None }) - } - let range_raw = range_raw.unwrap(); - - // First make sure that we only ever handle byte ranges - const PREFIX: &'static str = "bytes="; - if !range_raw.starts_with(PREFIX) { - return Outcome::Failure((Status::BadRequest, RangeError::Invalid)) - } - - // Next strip the 'bytes=' out and grab the only everything until either - // ',' - // ! Strip the comma if its there so we end up with a slice that matches - // [0-9]+-[0-9]+ - let range_raw = range_raw - .strip_prefix(PREFIX).unwrap(); - - if let Some(ranges) = range_raw.split_once('-') { - let start = ranges.0.parse::(); - let end = ranges.1.parse::().ok(); - println!("Range collected {:?} -> {:?}", start, end); - match (start, end) { - (Ok(start), Some(end)) => { - if end <= start { - println!("Start end range invalid {}->{}", start, end); - return Outcome::Failure((Status::BadRequest, RangeError::Malformed)) - } - return Outcome::Success(Self { - start, end: Some(end) - }) - } - (Ok(start), None) => { - return Outcome::Success(Self { start, end: None }) - } - _ => Outcome::Failure((Status::BadRequest, RangeError::Invalid)) - } - } else { - return Outcome::Failure((Status::BadRequest, RangeError::Invalid)); - } - } -} -