From b5b74876d670e037f598f745a6a244a5f84a81f5 Mon Sep 17 00:00:00 2001 From: Ivan Date: Fri, 9 Aug 2024 08:31:53 +0200 Subject: [PATCH] Sort playlist and fix playlist URL copy --- crates/librqbit/src/http_api.rs | 19 +++++++++++++------ crates/librqbit/webui/src/http-api.ts | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/crates/librqbit/src/http_api.rs b/crates/librqbit/src/http_api.rs index 7d1e5786..890f414c 100644 --- a/crates/librqbit/src/http_api.rs +++ b/crates/librqbit/src/http_api.rs @@ -142,7 +142,7 @@ impl HttpApi { .to_str() .context("hostname is not string")?; - let playlist_items = state + let mut playlist_items = state .api_torrent_details(idx)? .files .into_iter() @@ -157,15 +157,22 @@ impl HttpApi { .unwrap_or(false); if is_playable { let file_name = urlencoding::encode(&f.name); - Some(format!( - "http://{host}/torrents/{idx}/stream/{file_idx}/{file_name}" - )) + Some((file_name.into_owned(), file_idx)) } else { None } - }); + }) + .collect::>(); - Ok(playlist_items.collect::>().join("\r\n")) + playlist_items.sort(); + let list = playlist_items + .into_iter() + .map(|(file_name, file_idx)| { + format!("http://{host}/torrents/{idx}/stream/{file_idx}/{file_name}") + }) + .collect::>() + .join("\r\n"); + Ok(list) } async fn torrent_haves( diff --git a/crates/librqbit/webui/src/http-api.ts b/crates/librqbit/webui/src/http-api.ts index 16a3ea2c..ef6af660 100644 --- a/crates/librqbit/webui/src/http-api.ts +++ b/crates/librqbit/webui/src/http-api.ts @@ -152,6 +152,6 @@ export const API: RqbitAPI & { getVersion: () => Promise } = { return url; }, getPlaylistUrl: (index: number) => { - return apiUrl + `/torrents/${index}/playlist`; + return (apiUrl || window.origin) + `/torrents/${index}/playlist`; }, };