Encode file names in playlist

This commit is contained in:
Ivan 2024-08-05 09:30:26 +02:00
parent 510c2ee231
commit e7829bf213

View file

@ -1,6 +1,6 @@
use anyhow::Context; use anyhow::Context;
use axum::body::Bytes; use axum::body::Bytes;
use axum::extract::{Path, Query, Request, State}; use axum::extract::{Path, Query, State};
use axum::response::{IntoResponse, Redirect}; use axum::response::{IntoResponse, Redirect};
use axum::routing::{get, post}; use axum::routing::{get, post};
use futures::future::BoxFuture; use futures::future::BoxFuture;
@ -148,8 +148,7 @@ impl HttpApi {
.into_iter() .into_iter()
.enumerate() .enumerate()
.filter_map(|(file_idx, f)| { .filter_map(|(file_idx, f)| {
let file_name = f.name; let is_playable = mime_guess::from_path(&f.name)
let is_playable = mime_guess::from_path(&file_name)
.first() .first()
.map(|mime| { .map(|mime| {
mime.type_() == mime_guess::mime::VIDEO mime.type_() == mime_guess::mime::VIDEO
@ -157,6 +156,7 @@ impl HttpApi {
}) })
.unwrap_or(false); .unwrap_or(false);
if is_playable { if is_playable {
let file_name = urlencoding::encode(&f.name);
Some(format!( Some(format!(
"http://{host}/torrents/{idx}/stream/{file_idx}/{file_name}" "http://{host}/torrents/{idx}/stream/{file_idx}/{file_name}"
)) ))