diff --git a/src/main.rs b/src/main.rs index 88dcced..85d8094 100644 --- a/src/main.rs +++ b/src/main.rs @@ -330,11 +330,19 @@ fn handle_connection( let mut audio_path = path.clone(); let path = percent_decode_str(relative_path).decode_utf8_lossy(); - if path.contains('_') { - let path = path.replace('_', " "); - let _ = write!(stream, "HTTP/1.1 308 Permanent Redirect\r\n"); - let _ = write!(stream, "Location: /{path}\r\n\r\n"); - return; + if let Some((path, mut file)) = path.rsplit_once('/') { + println!("{path} -> {file}"); + if path.contains('_') { + let path = path.replace('_', " "); + let replaced_file; + if !file.contains('.') { + replaced_file = file.replace('_', " "); + file = &replaced_file; + } + let _ = write!(stream, "HTTP/1.1 308 Permanent Redirect\r\n"); + let _ = write!(stream, "Location: /{path}/{file}\r\n\r\n"); + return; + } } pk_path.push(format!("{path}.pk"));