A lot of changes to add hls support.

This commit is contained in:
euzu
2025-01-31 23:08:23 +01:00
parent 0c6e8cb6c8
commit 4889b77add
26 changed files with 549 additions and 218 deletions
+46
View File
@@ -31,6 +31,44 @@ use std::sync::Arc;
use url::Url;
use crate::api::model::active_client_stream::ActiveClientStream;
#[macro_export]
macro_rules! try_option_bad_request {
($option:expr, $msg_is_error:expr, $msg:expr) => {
match $option {
Some(value) => value,
None => {
if $msg_is_error {error!("{}", $msg);} else {debug!("{}", $msg);}
return HttpResponse::BadRequest().finish();
}
}
};
($option:expr) => {
match $option {
Some(value) => value,
None => return HttpResponse::BadRequest().finish(),
}
};
}
#[macro_export]
macro_rules! try_result_bad_request {
($option:expr, $msg_is_error:expr, $msg:expr) => {
match $option {
Ok(value) => value,
Err(_) => {
if $msg_is_error {error!("{}", $msg);} else {debug!("{}", $msg);}
return HttpResponse::BadRequest().finish();
}
}
};
($option:expr) => {
match $option {
Ok(value) => value,
Err(_) => return HttpResponse::BadRequest().finish(),
}
};
}
pub async fn serve_file(file_path: &Path, req: &HttpRequest, mime_type: mime::Mime) -> HttpResponse {
if file_path.exists() {
if let Ok(file) = actix_files::NamedFile::open_async(file_path).await {
@@ -250,3 +288,11 @@ pub async fn resource_response(app_state: &AppState, resource_url: &str, req: &H
}
HttpResponse::BadRequest().finish()
}
pub fn separate_number_and_remainder(input: &str) -> (String, Option<String>) {
input.rfind('.').map_or_else(|| (input.to_string(), None), |dot_index| {
let number_part = input[..dot_index].to_string();
let rest = input[dot_index..].to_string();
(number_part, if rest.len() < 2 { None } else { Some(rest) })
})
}