Skip to content

Commit

Permalink
More refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
izderadicka committed Oct 23, 2023
1 parent 1b4c263 commit 39d45c9
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,7 @@ impl<C: Send + 'static> MainService<C> {
.map(|l| FoldersOrdering::from_letter(l))
.unwrap_or(FoldersOrdering::Alphabetical);
if path.starts_with("/audio/") {
let user_agent = req.headers().typed_get::<UserAgent>();
MainService::<C>::serve_audio(
&req,
base_dir,
path,
transcoding,
params,
user_agent.as_ref().map(|ua| ua.as_str()),
)
.await
MainService::<C>::serve_audio(&req, base_dir, path, transcoding).await
} else if path.starts_with("/folder/") {
let group = params.get_string("group");
api::get_folder(
Expand Down Expand Up @@ -508,14 +499,15 @@ impl<C: Send + 'static> MainService<C> {
}
}

fn serve_audio(
async fn serve_audio(
req: &RequestWrapper,
base_dir: &'static Path,
path: &str,
transcoding: TranscodingDetails,
params: QueryParams,
user_agent: Option<&str>,
) -> ResponseFuture {
) -> ResponseResult {
let params = req.params();
let user_agent = req.headers().typed_get::<UserAgent>();
let user_agent = user_agent.as_ref().map(|ua| ua.as_str());
debug!(
"Received request with following headers {:?}",
req.headers()
Expand All @@ -527,10 +519,10 @@ impl<C: Send + 'static> MainService<C> {
Some(bytes_ranges) => {
if bytes_ranges.is_empty() {
error!("Range header without range bytes");
return response::fut(response::bad_request);
return Ok(response::bad_request());
} else if bytes_ranges.len() > 1 {
error!("Range with multiple ranges is not supported");
return response::fut(response::not_implemented);
return Ok(response::not_implemented());
} else {
Some(bytes_ranges[0])
}
Expand All @@ -552,6 +544,7 @@ impl<C: Send + 'static> MainService<C> {
transcoding,
transcoding_quality,
)
.await
}
}

Expand Down

0 comments on commit 39d45c9

Please sign in to comment.