Browse Source

don't use query with local filename

main v0.1.0
Georg Hopp 12 months ago
parent
commit
7f65e520ab
Signed by: ghopp GPG Key ID: 4C5D226768784538
  1. 28
      src/client.rs

28
src/client.rs

@ -111,8 +111,8 @@ impl State {
// I consider a missing path as fatal... there is absolutely nothing we can do about it // I consider a missing path as fatal... there is absolutely nothing we can do about it
// and we need all files from the playlist. // and we need all files from the playlist.
let path_and_query = uri.path_and_query().expect("No path and query").as_str();
let filename = Path::new(path_and_query)
let path = uri.path();
let filename = Path::new(path)
. file_name() . file_name()
. expect("no filename in path_and_query"); . expect("no filename in path_and_query");
let mut file = File::create(filename).await let mut file = File::create(filename).await
@ -163,17 +163,19 @@ impl State {
} }
} }
fn uri_relative_path_and_query(uri: &Uri) -> anyhow::Result<String>
fn uri_relative_path(uri: &Uri) -> anyhow::Result<String>
{ {
let filename = Path::new(uri.path())
Self::relative_path(uri.path())
}
fn relative_path(path: &str) -> anyhow::Result<String>
{
let filename = Path::new(path)
. file_name() . file_name()
. ok_or(anyhow!("name error"))? . ok_or(anyhow!("name error"))?
. to_str() . to_str()
. ok_or(anyhow!("Error getting filename from uri"))?; . ok_or(anyhow!("Error getting filename from uri"))?;
let query = uri.query()
. map(|q| "?".to_owned() + q)
. unwrap_or("".to_string());
Ok((filename.to_owned() + &query).to_string())
Ok(filename.to_string())
} }
async fn request(&mut self, uri: &Uri) -> anyhow::Result<Response<Body>> async fn request(&mut self, uri: &Uri) -> anyhow::Result<Response<Body>>
@ -198,11 +200,17 @@ impl State {
let mut new_segment = s.clone(); let mut new_segment = s.clone();
Ok(match Uri::try_from(s.uri.clone()) { Ok(match Uri::try_from(s.uri.clone()) {
Ok(uri) => { Ok(uri) => {
new_segment.uri = Self::uri_relative_path_and_query(&uri)?;
new_segment.uri = Self::uri_relative_path(&uri)?;
new_segment new_segment
} }
Err(_) => new_segment
Err(_) => {
let uri = s.uri.split_once('?')
. map(|(s,_)| s)
. unwrap_or(&s.uri);
new_segment.uri = Self::relative_path(uri)?;
new_segment
}
}) })
}).collect(); }).collect();

Loading…
Cancel
Save