@@ -13,7 +13,7 @@ use crate::models::category::CategoryId;
13
13
use crate :: models:: info_hash:: InfoHash ;
14
14
use crate :: models:: response:: TorrentsResponse ;
15
15
use crate :: models:: torrent:: { Metadata , TorrentListing } ;
16
- use crate :: models:: torrent_file:: { DbTorrent , DbTorrentAnnounceUrl , DbTorrentFile , Torrent , TorrentFile } ;
16
+ use crate :: models:: torrent_file:: { DbTorrent , DbTorrentAnnounceUrl , DbTorrentFile , DbTorrentHttpSeedUrl , Torrent , TorrentFile } ;
17
17
use crate :: models:: torrent_tag:: { TagId , TorrentTag } ;
18
18
use crate :: models:: tracker_key:: TrackerKey ;
19
19
use crate :: models:: user:: { User , UserAuthentication , UserCompact , UserId , UserProfile } ;
@@ -504,6 +504,8 @@ impl Database for Sqlite {
504
504
return Err ( e) ;
505
505
}
506
506
507
+ // add torrent files
508
+
507
509
let insert_torrent_files_result = if let Some ( length) = torrent. info . length {
508
510
query ( "INSERT INTO torrust_torrent_files (md5sum, torrent_id, length) VALUES (?, ?, ?)" )
509
511
. bind ( torrent. info . md5sum . clone ( ) )
@@ -538,6 +540,8 @@ impl Database for Sqlite {
538
540
return Err ( e) ;
539
541
}
540
542
543
+ // add announce URLs
544
+
541
545
let insert_torrent_announce_urls_result: Result < ( ) , database:: Error > = if let Some ( announce_urls) = & torrent. announce_list
542
546
{
543
547
// flatten the nested vec (this will however remove the)
@@ -572,7 +576,31 @@ impl Database for Sqlite {
572
576
return Err ( e) ;
573
577
}
574
578
575
- // Insert tags
579
+ // add HTTP seeds
580
+
581
+ let insert_torrent_http_seeds_result: Result < ( ) , database:: Error > = if let Some ( http_seeds) = & torrent. httpseeds {
582
+ for seed_url in http_seeds {
583
+ let ( ) = query ( "INSERT INTO torrust_torrent_http_seeds (torrent_id, seed_url) VALUES (?, ?)" )
584
+ . bind ( torrent_id)
585
+ . bind ( seed_url)
586
+ . execute ( & mut * tx)
587
+ . await
588
+ . map ( |_| ( ) )
589
+ . map_err ( |_| database:: Error :: Error ) ?;
590
+ }
591
+
592
+ Ok ( ( ) )
593
+ } else {
594
+ Ok ( ( ) )
595
+ } ;
596
+
597
+ // rollback transaction on error
598
+ if let Err ( e) = insert_torrent_http_seeds_result {
599
+ drop ( tx. rollback ( ) . await ) ;
600
+ return Err ( e) ;
601
+ }
602
+
603
+ // add tags
576
604
577
605
for tag_id in & metadata. tags {
578
606
let insert_torrent_tag_result = query ( "INSERT INTO torrust_torrent_tag_links (torrent_id, tag_id) VALUES (?, ?)" )
@@ -730,6 +758,15 @@ impl Database for Sqlite {
730
758
. map_err ( |_| database:: Error :: TorrentNotFound )
731
759
}
732
760
761
+ async fn get_torrent_http_seed_urls_from_id ( & self , torrent_id : i64 ) -> Result < Vec < String > , database:: Error > {
762
+ query_as :: < _ , DbTorrentHttpSeedUrl > ( "SELECT seed_url FROM torrust_torrent_http_seeds WHERE torrent_id = ?" )
763
+ . bind ( torrent_id)
764
+ . fetch_all ( & self . pool )
765
+ . await
766
+ . map ( |v| v. iter ( ) . map ( |a| a. seed_url . to_string ( ) ) . collect ( ) )
767
+ . map_err ( |_| database:: Error :: TorrentNotFound )
768
+ }
769
+
733
770
async fn get_torrent_listing_from_id ( & self , torrent_id : i64 ) -> Result < TorrentListing , database:: Error > {
734
771
query_as :: < _ , TorrentListing > (
735
772
"SELECT
0 commit comments