11use hightorrent:: {
2- InfoHash , MultiTarget , SingleTarget , ToTorrent , Torrent , TorrentID , TorrentList , Tracker ,
3- TryIntoTracker ,
2+ InfoHash , MultiTarget , SingleTarget , ToTorrent , ToTorrentContent , Torrent ,
3+ TorrentContent , TorrentID , TorrentList , Tracker , TryIntoTracker ,
44} ;
55use reqwest:: multipart:: Form ;
66use reqwest:: multipart:: Part ;
@@ -14,7 +14,7 @@ use std::borrow::Borrow;
1414use crate :: {
1515 api:: * ,
1616 api_error:: { ApiError as Error , * } ,
17- qbittorrent:: { QBittorrentTorrent , QBittorrentTracker } ,
17+ qbittorrent:: { QBittorrentTorrent , QBittorrentTorrentContent , QBittorrentTracker } ,
1818} ;
1919
2020#[ derive( Clone ) ]
@@ -296,6 +296,32 @@ impl Api for QBittorrentClient {
296296 } )
297297 }
298298 }
299+
300+ async fn get_files ( & self , target : & SingleTarget ) -> Result < Vec < TorrentContent > , Error > {
301+ let Some ( id) = self . id ( target) . await ? else {
302+ return Err ( Error :: MissingTorrent {
303+ hash : target. as_str ( ) . to_string ( ) ,
304+ } ) ;
305+ } ;
306+
307+ let mut form = Form :: new ( ) ;
308+ form = form. text ( "hash" , id. as_str ( ) . to_string ( ) ) ;
309+ let res = self
310+ . _post_multipart ( self . _endpoint ( "torrents/files" ) , form)
311+ . await ?;
312+
313+ if res. status ( ) . is_success ( ) {
314+ let concrete: Vec < QBittorrentTorrentContent > = self . _json ( res) . await ?;
315+ Ok ( concrete
316+ . iter ( )
317+ . map ( |t| t. to_torrent_content ( ) )
318+ . collect ( ) )
319+ } else {
320+ Err ( Error :: MissingTorrent {
321+ hash : target. as_str ( ) . to_string ( ) ,
322+ } )
323+ }
324+ }
299325}
300326
301327#[ async_trait]
0 commit comments