Merge pull request #171 from izderadicka/playlist-sorted

Sort playlist and fix playlist URL copy
This commit is contained in:
Igor Katson 2024-08-09 08:25:14 +01:00 committed by GitHub
commit fb72b1b26b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 7 deletions

View file

@ -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::<Vec<_>>();
Ok(playlist_items.collect::<Vec<_>>().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::<Vec<_>>()
.join("\r\n");
Ok(list)
}
async fn torrent_haves(

View file

@ -152,6 +152,6 @@ export const API: RqbitAPI & { getVersion: () => Promise<string> } = {
return url;
},
getPlaylistUrl: (index: number) => {
return apiUrl + `/torrents/${index}/playlist`;
return (apiUrl || window.origin) + `/torrents/${index}/playlist`;
},
};