feat: Make a builder function for the stream request route

This commit is contained in:
kale 2024-06-03 20:00:06 +02:00
parent e2587692a8
commit bbb2e2c8ea
Signed by: kalmenn
GPG key ID: F500055C44BC3834

View file

@ -2,7 +2,7 @@ pub mod error;
use error::{handle_rejection, InternalServerError, NotFoundError};
use hyper::{body, Body};
use std::{path::PathBuf, time::Duration};
use std::path::PathBuf;
use bytes::Bytes;
use clap::Parser as _;
@ -16,7 +16,7 @@ use warp::{
Filter,
};
#[derive(clap::Parser)]
#[derive(clap::Parser, Clone)]
pub struct Args {
music_dir: PathBuf,
}
@ -29,17 +29,24 @@ async fn main() {
let route = warp::get()
.and(warp::path("track"))
.and(any().map(move || config))
.and(warp::header::headers_cloned())
.and(param())
.and_then(serve_local_tracks);
.and(serve_local_tracks(config));
warp::serve(route.recover(handle_rejection))
.run(([127, 0, 0, 1], 8080))
.await;
}
pub async fn serve_local_tracks(
pub fn serve_local_tracks(
config: &'static Args,
) -> impl Filter<Extract = (warp::reply::Response,), Error = Rejection> + Clone {
any()
.map(move || config)
.and(warp::header::headers_cloned())
.and(param())
.and_then(handle_file_request)
}
pub async fn handle_file_request(
config: &Args,
_headers: HeaderMap,
// TODO: request files based off of their MusicBrainz Identifier instead