feat: implement local-files feature with various enhancements and cleanup
This commit is contained in:
@@ -11,7 +11,7 @@ use axum::Router;
|
||||
use axum::extract::{Path, State};
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::IntoResponse;
|
||||
use axum::routing::{get, post, put, delete};
|
||||
use axum::routing::{get, post, put};
|
||||
use axum::Json;
|
||||
use domain::errors::DomainResult;
|
||||
use domain::ProviderConfigRow;
|
||||
|
||||
@@ -8,6 +8,7 @@ pub fn router() -> Router<AppState> {
|
||||
Router::new().route("/", get(get_config))
|
||||
}
|
||||
|
||||
#[allow(clippy::vec_init_then_push)]
|
||||
async fn get_config(State(state): State<AppState>) -> Json<ConfigResponse> {
|
||||
let registry = state.provider_registry.read().await;
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ pub fn router() -> Router<AppState> {
|
||||
// Direct streaming
|
||||
// ============================================================================
|
||||
|
||||
#[cfg_attr(not(feature = "local-files"), allow(unused_variables))]
|
||||
async fn stream_file(
|
||||
State(state): State<AppState>,
|
||||
Path(encoded_id): Path<String>,
|
||||
@@ -131,7 +132,7 @@ async fn stream_file(
|
||||
);
|
||||
}
|
||||
|
||||
return builder.body(body).map_err(|e| ApiError::internal(e.to_string()));
|
||||
builder.body(body).map_err(|e| ApiError::internal(e.to_string()))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "local-files"))]
|
||||
@@ -316,6 +317,7 @@ async fn clear_transcode_cache(
|
||||
// Helpers
|
||||
// ============================================================================
|
||||
|
||||
#[cfg(feature = "local-files")]
|
||||
fn content_type_for_ext(ext: &str) -> &'static str {
|
||||
match ext {
|
||||
"mp4" | "m4v" => "video/mp4",
|
||||
@@ -327,6 +329,7 @@ fn content_type_for_ext(ext: &str) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "local-files")]
|
||||
fn parse_range(range: &str, file_size: u64) -> Option<(u64, u64)> {
|
||||
let range = range.strip_prefix("bytes=")?;
|
||||
let (start_str, end_str) = range.split_once('-')?;
|
||||
|
||||
Reference in New Issue
Block a user