From f2369b417c6a294976328fb158e4274335023e6b Mon Sep 17 00:00:00 2001 From: MMelchor Date: Sat, 2 Sep 2023 17:48:01 +0200 Subject: [PATCH] feat: [#264] Added torrent name to list and detail endpoints The list and detail torrent endpoints now contain the torrent name: For example: { "data": { "torrent_id": 175, "uploader": "admin", "info_hash": "124f00ff15f00ae19d7b939950090cb42ab6e852", "title": "www", "description": "www", "category": { "category_id": 63, "name": "Paper", "num_torrents": 4 }, "upload_date": "2023-08-26 20:02:27", "file_size": 639140, "seeders": 0, "leechers": 0, "files": [ { "path": [ "mandelbrot_set_07" ], "length": 639140, "md5sum": null } ], "trackers": [ "udp://localhost:6969", "udp://localhost:6969" ], "magnet_link": "magnet:?xt=urn:btih:124f00ff15f00ae19d7b939950090cb42ab6e852&dn=www&tr=udp%3A%2F%2Flocalhost%3A6969&tr=udp%3A%2F%2Flocalhost%3A6969", "tags": [], "name": "mandelbrot_set_07" } } Notice the last field `name`. That field is in the table column `torrust_torrents::name`. It's going to be used in the frontend to set the name for the downloaded torrent file. --- src/databases/mysql.rs | 6 +++--- src/databases/sqlite.rs | 6 +++--- src/models/response.rs | 2 ++ src/models/torrent.rs | 1 + 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/databases/mysql.rs b/src/databases/mysql.rs index e7d0babb..cb7b3317 100644 --- a/src/databases/mysql.rs +++ b/src/databases/mysql.rs @@ -375,7 +375,7 @@ impl Database for Mysql { }; let mut query_string = format!( - "SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, DATE_FORMAT(tt.date_uploaded, '%Y-%m-%d %H:%i:%s') AS date_uploaded, tt.size AS file_size, + "SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, DATE_FORMAT(tt.date_uploaded, '%Y-%m-%d %H:%i:%s') AS date_uploaded, tt.size AS file_size, tt.name, CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders, CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers FROM torrust_torrents tt @@ -629,7 +629,7 @@ impl Database for Mysql { async fn get_torrent_listing_from_id(&self, torrent_id: i64) -> Result { query_as::<_, TorrentListing>( - "SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, DATE_FORMAT(tt.date_uploaded, '%Y-%m-%d %H:%i:%s') AS date_uploaded, tt.size AS file_size, + "SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, DATE_FORMAT(tt.date_uploaded, '%Y-%m-%d %H:%i:%s') AS date_uploaded, tt.size AS file_size, tt.name, CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders, CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers FROM torrust_torrents tt @@ -647,7 +647,7 @@ impl Database for Mysql { async fn get_torrent_listing_from_info_hash(&self, info_hash: &InfoHash) -> Result { query_as::<_, TorrentListing>( - "SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, DATE_FORMAT(tt.date_uploaded, '%Y-%m-%d %H:%i:%s') AS date_uploaded, tt.size AS file_size, + "SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, DATE_FORMAT(tt.date_uploaded, '%Y-%m-%d %H:%i:%s') AS date_uploaded, tt.size AS file_size, tt.name, CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders, CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers FROM torrust_torrents tt diff --git a/src/databases/sqlite.rs b/src/databases/sqlite.rs index c300c188..14aa8808 100644 --- a/src/databases/sqlite.rs +++ b/src/databases/sqlite.rs @@ -363,7 +363,7 @@ impl Database for Sqlite { }; let mut query_string = format!( - "SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, tt.date_uploaded, tt.size AS file_size, + "SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, tt.date_uploaded, tt.size AS file_size, tt.name, CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders, CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers FROM torrust_torrents tt @@ -617,7 +617,7 @@ impl Database for Sqlite { async fn get_torrent_listing_from_id(&self, torrent_id: i64) -> Result { query_as::<_, TorrentListing>( - "SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, tt.date_uploaded, tt.size AS file_size, + "SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, tt.date_uploaded, tt.size AS file_size, tt.name, CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders, CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers FROM torrust_torrents tt @@ -635,7 +635,7 @@ impl Database for Sqlite { async fn get_torrent_listing_from_info_hash(&self, info_hash: &InfoHash) -> Result { query_as::<_, TorrentListing>( - "SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, tt.date_uploaded, tt.size AS file_size, + "SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, tt.date_uploaded, tt.size AS file_size, tt.name, CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders, CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers FROM torrust_torrents tt diff --git a/src/models/response.rs b/src/models/response.rs index cd8b4f59..adb1de07 100644 --- a/src/models/response.rs +++ b/src/models/response.rs @@ -61,6 +61,7 @@ pub struct TorrentResponse { pub trackers: Vec, pub magnet_link: String, pub tags: Vec, + pub name: String, } impl TorrentResponse { @@ -81,6 +82,7 @@ impl TorrentResponse { trackers: vec![], magnet_link: String::new(), tags: vec![], + name: torrent_listing.name, } } } diff --git a/src/models/torrent.rs b/src/models/torrent.rs index 66a9616d..eb2bcde2 100644 --- a/src/models/torrent.rs +++ b/src/models/torrent.rs @@ -20,6 +20,7 @@ pub struct TorrentListing { pub file_size: i64, pub seeders: i64, pub leechers: i64, + pub name: String, } #[derive(Debug, Deserialize)]