From f0ad6a442f93560c61eda5296b1cfe26f48299a3 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 18 Sep 2023 17:18:48 +0100 Subject: [PATCH] refactor: rename structs and reorganize mods --- src/databases/database.rs | 18 +- src/databases/mysql.rs | 10 +- src/databases/sqlite.rs | 10 +- src/models/torrent_file.rs | 249 +++++++++--------- src/services/torrent.rs | 4 +- src/services/torrent_file.rs | 75 +++++- .../databases/sqlite_v2_0_0.rs | 4 +- 7 files changed, 215 insertions(+), 155 deletions(-) diff --git a/src/databases/database.rs b/src/databases/database.rs index 8fc10d79..e5778649 100644 --- a/src/databases/database.rs +++ b/src/databases/database.rs @@ -8,7 +8,7 @@ use crate::models::category::CategoryId; use crate::models::info_hash::InfoHash; use crate::models::response::TorrentsResponse; use crate::models::torrent::TorrentListing; -use crate::models::torrent_file::{DbTorrentInfo, Torrent, TorrentFile}; +use crate::models::torrent_file::{DbTorrent, Torrent, TorrentFile}; use crate::models::torrent_tag::{TagId, TorrentTag}; use crate::models::tracker_key::TrackerKey; use crate::models::user::{User, UserAuthentication, UserCompact, UserId, UserProfile}; @@ -209,11 +209,7 @@ pub trait Database: Sync + Send { let torrent_announce_urls = self.get_torrent_announce_urls_from_id(torrent_info.torrent_id).await?; - Ok(Torrent::from_db_info_files_and_announce_urls( - torrent_info, - torrent_files, - torrent_announce_urls, - )) + Ok(Torrent::from_database(torrent_info, torrent_files, torrent_announce_urls)) } /// Get `Torrent` from `torrent_id`. @@ -224,11 +220,7 @@ pub trait Database: Sync + Send { let torrent_announce_urls = self.get_torrent_announce_urls_from_id(torrent_id).await?; - Ok(Torrent::from_db_info_files_and_announce_urls( - torrent_info, - torrent_files, - torrent_announce_urls, - )) + Ok(Torrent::from_database(torrent_info, torrent_files, torrent_announce_urls)) } /// It returns the list of all infohashes producing the same canonical @@ -257,10 +249,10 @@ pub trait Database: Sync + Send { async fn add_info_hash_to_canonical_info_hash_group(&self, original: &InfoHash, canonical: &InfoHash) -> Result<(), Error>; /// Get torrent's info as `DbTorrentInfo` from `torrent_id`. - async fn get_torrent_info_from_id(&self, torrent_id: i64) -> Result; + async fn get_torrent_info_from_id(&self, torrent_id: i64) -> Result; /// Get torrent's info as `DbTorrentInfo` from torrent `InfoHash`. - async fn get_torrent_info_from_info_hash(&self, info_hash: &InfoHash) -> Result; + async fn get_torrent_info_from_info_hash(&self, info_hash: &InfoHash) -> Result; /// Get all torrent's files as `Vec` from `torrent_id`. async fn get_torrent_files_from_id(&self, torrent_id: i64) -> Result, Error>; diff --git a/src/databases/mysql.rs b/src/databases/mysql.rs index 550a3d7d..f793e5cb 100644 --- a/src/databases/mysql.rs +++ b/src/databases/mysql.rs @@ -13,7 +13,7 @@ use crate::models::category::CategoryId; use crate::models::info_hash::InfoHash; use crate::models::response::TorrentsResponse; use crate::models::torrent::TorrentListing; -use crate::models::torrent_file::{DbTorrentAnnounceUrl, DbTorrentFile, DbTorrentInfo, Torrent, TorrentFile}; +use crate::models::torrent_file::{DbTorrent, DbTorrentAnnounceUrl, DbTorrentFile, Torrent, TorrentFile}; use crate::models::torrent_tag::{TagId, TorrentTag}; use crate::models::tracker_key::TrackerKey; use crate::models::user::{User, UserAuthentication, UserCompact, UserId, UserProfile}; @@ -676,16 +676,16 @@ impl Database for Mysql { .map_err(|err| database::Error::ErrorWithText(err.to_string())) } - async fn get_torrent_info_from_id(&self, torrent_id: i64) -> Result { - query_as::<_, DbTorrentInfo>("SELECT * FROM torrust_torrents WHERE torrent_id = ?") + async fn get_torrent_info_from_id(&self, torrent_id: i64) -> Result { + query_as::<_, DbTorrent>("SELECT * FROM torrust_torrents WHERE torrent_id = ?") .bind(torrent_id) .fetch_one(&self.pool) .await .map_err(|_| database::Error::TorrentNotFound) } - async fn get_torrent_info_from_info_hash(&self, info_hash: &InfoHash) -> Result { - query_as::<_, DbTorrentInfo>("SELECT * FROM torrust_torrents WHERE info_hash = ?") + async fn get_torrent_info_from_info_hash(&self, info_hash: &InfoHash) -> Result { + query_as::<_, DbTorrent>("SELECT * FROM torrust_torrents WHERE info_hash = ?") .bind(info_hash.to_hex_string().to_lowercase()) .fetch_one(&self.pool) .await diff --git a/src/databases/sqlite.rs b/src/databases/sqlite.rs index 9a0dae7a..980e7a3b 100644 --- a/src/databases/sqlite.rs +++ b/src/databases/sqlite.rs @@ -13,7 +13,7 @@ use crate::models::category::CategoryId; use crate::models::info_hash::InfoHash; use crate::models::response::TorrentsResponse; use crate::models::torrent::TorrentListing; -use crate::models::torrent_file::{DbTorrentAnnounceUrl, DbTorrentFile, DbTorrentInfo, Torrent, TorrentFile}; +use crate::models::torrent_file::{DbTorrent, DbTorrentAnnounceUrl, DbTorrentFile, Torrent, TorrentFile}; use crate::models::torrent_tag::{TagId, TorrentTag}; use crate::models::tracker_key::TrackerKey; use crate::models::user::{User, UserAuthentication, UserCompact, UserId, UserProfile}; @@ -666,16 +666,16 @@ impl Database for Sqlite { .map_err(|err| database::Error::ErrorWithText(err.to_string())) } - async fn get_torrent_info_from_id(&self, torrent_id: i64) -> Result { - query_as::<_, DbTorrentInfo>("SELECT * FROM torrust_torrents WHERE torrent_id = ?") + async fn get_torrent_info_from_id(&self, torrent_id: i64) -> Result { + query_as::<_, DbTorrent>("SELECT * FROM torrust_torrents WHERE torrent_id = ?") .bind(torrent_id) .fetch_one(&self.pool) .await .map_err(|_| database::Error::TorrentNotFound) } - async fn get_torrent_info_from_info_hash(&self, info_hash: &InfoHash) -> Result { - query_as::<_, DbTorrentInfo>("SELECT * FROM torrust_torrents WHERE info_hash = ?") + async fn get_torrent_info_from_info_hash(&self, info_hash: &InfoHash) -> Result { + query_as::<_, DbTorrent>("SELECT * FROM torrust_torrents WHERE info_hash = ?") .bind(info_hash.to_hex_string().to_lowercase()) .fetch_one(&self.pool) .await diff --git a/src/models/torrent_file.rs b/src/models/torrent_file.rs index effd0f48..ace9f9fa 100644 --- a/src/models/torrent_file.rs +++ b/src/models/torrent_file.rs @@ -5,22 +5,38 @@ use sha1::{Digest, Sha1}; use super::info_hash::InfoHash; use crate::config::Configuration; -use crate::services::torrent_file::NewTorrentInfoRequest; +use crate::services::torrent_file::CreateTorrentRequest; use crate::utils::hex::{from_bytes, into_bytes}; -#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] -pub struct TorrentNode(String, i64); - -#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] -pub struct TorrentFile { - pub path: Vec, - pub length: i64, +#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)] +pub struct Torrent { + pub info: TorrentInfoDictionary, // #[serde(default)] - pub md5sum: Option, + pub announce: Option, + #[serde(default)] + pub nodes: Option>, + #[serde(default)] + pub encoding: Option, + #[serde(default)] + pub httpseeds: Option>, + #[serde(default)] + #[serde(rename = "announce-list")] + pub announce_list: Option>>, + #[serde(default)] + #[serde(rename = "creation date")] + pub creation_date: Option, + #[serde(default)] + pub comment: Option, + #[serde(default)] + #[serde(rename = "created by")] + pub created_by: Option, } #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] -pub struct TorrentInfo { +pub struct TorrentNode(String, i64); + +#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] +pub struct TorrentInfoDictionary { pub name: String, #[serde(default)] pub pieces: Option, @@ -43,108 +59,79 @@ pub struct TorrentInfo { pub source: Option, } -impl TorrentInfo { - /// torrent file can only hold a pieces key or a root hash key: - /// [BEP 39](http://www.bittorrent.org/beps/bep_0030.html) - #[must_use] - pub fn get_pieces_as_string(&self) -> String { - match &self.pieces { - None => String::new(), - Some(byte_buf) => from_bytes(byte_buf.as_ref()), - } - } +#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] +pub struct TorrentFile { + pub path: Vec, + pub length: i64, + #[serde(default)] + pub md5sum: Option, +} - /// It returns the root hash as a `i64` value. +impl Torrent { + /// It builds a `Torrent` from a request. /// /// # Panics /// - /// This function will panic if the root hash cannot be converted into a - /// `i64` value. + /// This function will panic if the `torrent_info.pieces` is not a valid hex string. #[must_use] - pub fn get_root_hash_as_i64(&self) -> i64 { - match &self.root_hash { - None => 0i64, - Some(root_hash) => root_hash - .parse::() - .expect("variable `root_hash` cannot be converted into a `i64`"), - } - } + pub fn from_request(create_torrent_req: CreateTorrentRequest) -> Self { + let info_dict = create_torrent_req.build_info_dictionary(); - #[must_use] - pub fn is_a_single_file_torrent(&self) -> bool { - self.length.is_some() - } - - #[must_use] - pub fn is_a_multiple_file_torrent(&self) -> bool { - self.files.is_some() + Self { + info: info_dict, + announce: None, + nodes: None, + encoding: None, + httpseeds: None, + announce_list: Some(create_torrent_req.announce_urls), + creation_date: None, + comment: create_torrent_req.comment, + created_by: None, + } } -} -#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)] -pub struct Torrent { - pub info: TorrentInfo, // - #[serde(default)] - pub announce: Option, - #[serde(default)] - pub nodes: Option>, - #[serde(default)] - pub encoding: Option, - #[serde(default)] - pub httpseeds: Option>, - #[serde(default)] - #[serde(rename = "announce-list")] - pub announce_list: Option>>, - #[serde(default)] - #[serde(rename = "creation date")] - pub creation_date: Option, - #[serde(default)] - pub comment: Option, - #[serde(default)] - #[serde(rename = "created by")] - pub created_by: Option, -} - -impl Torrent { - /// It builds a `Torrent` from a `NewTorrentInfoRequest`. + /// It hydrates a `Torrent` struct from the database data. /// /// # Panics /// - /// This function will panic if the `torrent_info.pieces` is not a valid hex string. + /// This function will panic if the `torrent_info.pieces` is not a valid + /// hex string. #[must_use] - pub fn from_new_torrent_info_request(torrent_info: NewTorrentInfoRequest) -> Self { - // the info part of the torrent file - let mut info = TorrentInfo { - name: torrent_info.name.to_string(), + pub fn from_database( + db_torrent: DbTorrent, + torrent_files: Vec, + torrent_announce_urls: Vec>, + ) -> Self { + let mut info_dict = TorrentInfoDictionary { + name: db_torrent.name, pieces: None, - piece_length: torrent_info.piece_length, + piece_length: db_torrent.piece_length, md5sum: None, length: None, files: None, - private: torrent_info.private, + private: db_torrent.private, path: None, root_hash: None, source: None, }; // a torrent file has a root hash or a pieces key, but not both. - if torrent_info.root_hash > 0 { - info.root_hash = Some(torrent_info.pieces); + if db_torrent.root_hash > 0 { + info_dict.root_hash = Some(db_torrent.pieces); } else { - let pieces = into_bytes(&torrent_info.pieces).expect("variable `torrent_info.pieces` is not a valid hex string"); - info.pieces = Some(ByteBuf::from(pieces)); + let buffer = into_bytes(&db_torrent.pieces).expect("variable `torrent_info.pieces` is not a valid hex string"); + info_dict.pieces = Some(ByteBuf::from(buffer)); } // either set the single file or the multiple files information - if torrent_info.files.len() == 1 { - let torrent_file = torrent_info - .files + if torrent_files.len() == 1 { + let torrent_file = torrent_files .first() .expect("vector `torrent_files` should have at least one element"); - info.md5sum = torrent_file.md5sum.clone(); + info_dict.md5sum = torrent_file.md5sum.clone(); - info.length = Some(torrent_file.length); + info_dict.length = Some(torrent_file.length); let path = if torrent_file .path @@ -158,44 +145,24 @@ impl Torrent { Some(torrent_file.path.clone()) }; - info.path = path; + info_dict.path = path; } else { - info.files = Some(torrent_info.files); + info_dict.files = Some(torrent_files); } Self { - info, + info: info_dict, announce: None, nodes: None, encoding: None, httpseeds: None, - announce_list: Some(torrent_info.announce_urls), + announce_list: Some(torrent_announce_urls), creation_date: None, - comment: torrent_info.comment, + comment: db_torrent.comment.clone(), created_by: None, } } - /// It hydrates a `Torrent` struct from the database data. - #[must_use] - pub fn from_db_info_files_and_announce_urls( - torrent_info: DbTorrentInfo, - torrent_files: Vec, - torrent_announce_urls: Vec>, - ) -> Self { - let torrent_info_request = NewTorrentInfoRequest { - name: torrent_info.name, - pieces: torrent_info.pieces, - piece_length: torrent_info.piece_length, - private: torrent_info.private, - root_hash: torrent_info.root_hash, - files: torrent_files, - announce_urls: torrent_announce_urls, - comment: torrent_info.comment, - }; - Torrent::from_new_torrent_info_request(torrent_info_request) - } - /// Sets the announce url to the tracker url and removes all other trackers /// if the torrent is private. pub async fn set_announce_urls(&mut self, cfg: &Configuration) { @@ -278,17 +245,46 @@ impl Torrent { } } -#[allow(clippy::module_name_repetitions)] -#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize, sqlx::FromRow)] -pub struct DbTorrentFile { - pub path: Option, - pub length: i64, - #[serde(default)] - pub md5sum: Option, +impl TorrentInfoDictionary { + /// torrent file can only hold a pieces key or a root hash key: + /// [BEP 39](http://www.bittorrent.org/beps/bep_0030.html) + #[must_use] + pub fn get_pieces_as_string(&self) -> String { + match &self.pieces { + None => String::new(), + Some(byte_buf) => from_bytes(byte_buf.as_ref()), + } + } + + /// It returns the root hash as a `i64` value. + /// + /// # Panics + /// + /// This function will panic if the root hash cannot be converted into a + /// `i64` value. + #[must_use] + pub fn get_root_hash_as_i64(&self) -> i64 { + match &self.root_hash { + None => 0i64, + Some(root_hash) => root_hash + .parse::() + .expect("variable `root_hash` cannot be converted into a `i64`"), + } + } + + #[must_use] + pub fn is_a_single_file_torrent(&self) -> bool { + self.length.is_some() + } + + #[must_use] + pub fn is_a_multiple_file_torrent(&self) -> bool { + self.files.is_some() + } } #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize, sqlx::FromRow)] -pub struct DbTorrentInfo { +pub struct DbTorrent { pub torrent_id: i64, pub info_hash: String, pub name: String, @@ -300,6 +296,15 @@ pub struct DbTorrentInfo { pub comment: Option, } +#[allow(clippy::module_name_repetitions)] +#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize, sqlx::FromRow)] +pub struct DbTorrentFile { + pub path: Option, + pub length: i64, + #[serde(default)] + pub md5sum: Option, +} + #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize, sqlx::FromRow)] pub struct DbTorrentAnnounceUrl { pub tracker_url: String, @@ -312,7 +317,7 @@ mod tests { use serde_bytes::ByteBuf; - use crate::models::torrent_file::{Torrent, TorrentInfo}; + use crate::models::torrent_file::{Torrent, TorrentInfoDictionary}; #[test] fn the_parsed_torrent_file_should_calculated_the_torrent_info_hash() { @@ -349,7 +354,7 @@ mod tests { let sample_data_in_txt_file = "mandelbrot\n"; - let info = TorrentInfo { + let info = TorrentInfoDictionary { name: "sample.txt".to_string(), pieces: Some(ByteBuf::from(vec![ // D4 91 58 7F 1C 42 DF F0 CB 0F F5 C2 B8 CE FE 22 B3 AD 31 0A // hex @@ -384,13 +389,13 @@ mod tests { use serde_bytes::ByteBuf; - use crate::models::torrent_file::{Torrent, TorrentFile, TorrentInfo}; + use crate::models::torrent_file::{Torrent, TorrentFile, TorrentInfoDictionary}; #[test] fn a_simple_single_file_torrent() { let sample_data_in_txt_file = "mandelbrot\n"; - let info = TorrentInfo { + let info = TorrentInfoDictionary { name: "sample.txt".to_string(), pieces: Some(ByteBuf::from(vec![ // D4 91 58 7F 1C 42 DF F0 CB 0F F5 C2 B8 CE FE 22 B3 AD 31 0A // hex @@ -425,7 +430,7 @@ mod tests { fn a_simple_multi_file_torrent() { let sample_data_in_txt_file = "mandelbrot\n"; - let info = TorrentInfo { + let info = TorrentInfoDictionary { name: "sample".to_string(), pieces: Some(ByteBuf::from(vec![ // D4 91 58 7F 1C 42 DF F0 CB 0F F5 C2 B8 CE FE 22 B3 AD 31 0A // hex @@ -464,7 +469,7 @@ mod tests { fn a_simple_single_file_torrent_with_a_source() { let sample_data_in_txt_file = "mandelbrot\n"; - let info = TorrentInfo { + let info = TorrentInfoDictionary { name: "sample.txt".to_string(), pieces: Some(ByteBuf::from(vec![ // D4 91 58 7F 1C 42 DF F0 CB 0F F5 C2 B8 CE FE 22 B3 AD 31 0A // hex @@ -499,7 +504,7 @@ mod tests { fn a_simple_single_file_private_torrent() { let sample_data_in_txt_file = "mandelbrot\n"; - let info = TorrentInfo { + let info = TorrentInfoDictionary { name: "sample.txt".to_string(), pieces: Some(ByteBuf::from(vec![ // D4 91 58 7F 1C 42 DF F0 CB 0F F5 C2 B8 CE FE 22 B3 AD 31 0A // hex diff --git a/src/services/torrent.rs b/src/services/torrent.rs index 7dce0db1..71c8fb48 100644 --- a/src/services/torrent.rs +++ b/src/services/torrent.rs @@ -13,7 +13,7 @@ use crate::models::category::CategoryId; use crate::models::info_hash::InfoHash; use crate::models::response::{DeletedTorrentResponse, TorrentResponse, TorrentsResponse}; use crate::models::torrent::{Metadata, TorrentId, TorrentListing}; -use crate::models::torrent_file::{DbTorrentInfo, Torrent, TorrentFile}; +use crate::models::torrent_file::{DbTorrent, Torrent, TorrentFile}; use crate::models::torrent_tag::{TagId, TorrentTag}; use crate::models::user::UserId; use crate::tracker::statistics_importer::StatisticsImporter; @@ -649,7 +649,7 @@ impl DbTorrentInfoRepository { /// # Errors /// /// This function will return an error there is a database error. - pub async fn get_by_info_hash(&self, info_hash: &InfoHash) -> Result { + pub async fn get_by_info_hash(&self, info_hash: &InfoHash) -> Result { self.database.get_torrent_info_from_info_hash(info_hash).await } diff --git a/src/services/torrent_file.rs b/src/services/torrent_file.rs index dbfa72f5..3b180ab2 100644 --- a/src/services/torrent_file.rs +++ b/src/services/torrent_file.rs @@ -1,14 +1,16 @@ //! This module contains the services related to torrent file management. +use serde_bytes::ByteBuf; use uuid::Uuid; -use crate::models::torrent_file::{Torrent, TorrentFile}; +use crate::models::torrent_file::{Torrent, TorrentFile, TorrentInfoDictionary}; use crate::services::hasher::sha1; +use crate::utils::hex::into_bytes; /// It contains the information required to create a new torrent file. /// /// It's not the full in-memory representation of a torrent file. The full /// in-memory representation is the `Torrent` struct. -pub struct NewTorrentInfoRequest { +pub struct CreateTorrentRequest { // The `info` dictionary fields pub name: String, pub pieces: String, @@ -21,6 +23,67 @@ pub struct NewTorrentInfoRequest { pub comment: Option, } +impl CreateTorrentRequest { + /// It builds a `TorrentInfoDictionary` from the current torrent request. + /// + /// # Panics + /// + /// This function will panic if the `pieces` field is not a valid hex string. + #[must_use] + pub fn build_info_dictionary(&self) -> TorrentInfoDictionary { + let mut info_dict = TorrentInfoDictionary { + name: self.name.to_string(), + pieces: None, + piece_length: self.piece_length, + md5sum: None, + length: None, + files: None, + private: self.private, + path: None, + root_hash: None, + source: None, + }; + + // a torrent file has a root hash or a pieces key, but not both. + if self.root_hash > 0 { + info_dict.root_hash = Some(self.pieces.clone()); + } else { + let buffer = into_bytes(&self.pieces).expect("variable `torrent_info.pieces` is not a valid hex string"); + info_dict.pieces = Some(ByteBuf::from(buffer)); + } + + // either set the single file or the multiple files information + if self.files.len() == 1 { + let torrent_file = self + .files + .first() + .expect("vector `torrent_files` should have at least one element"); + + info_dict.md5sum = torrent_file.md5sum.clone(); + + info_dict.length = Some(torrent_file.length); + + let path = if torrent_file + .path + .first() + .as_ref() + .expect("the vector for the `path` should have at least one element") + .is_empty() + { + None + } else { + Some(torrent_file.path.clone()) + }; + + info_dict.path = path; + } else { + info_dict.files = Some(self.files.clone()); + } + + info_dict + } +} + /// It generates a random single-file torrent for testing purposes. /// /// The torrent will contain a single text file with the UUID as its content. @@ -43,7 +106,7 @@ pub fn generate_random_torrent(id: Uuid) -> Torrent { let torrent_announce_urls: Vec> = vec![]; - let torrent_info_request = NewTorrentInfoRequest { + let torrent_info_request = CreateTorrentRequest { name: format!("file-{id}.txt"), pieces: sha1(&file_contents), piece_length: 16384, @@ -54,7 +117,7 @@ pub fn generate_random_torrent(id: Uuid) -> Torrent { comment: None, }; - Torrent::from_new_torrent_info_request(torrent_info_request) + Torrent::from_request(torrent_info_request) } #[cfg(test)] @@ -62,7 +125,7 @@ mod tests { use serde_bytes::ByteBuf; use uuid::Uuid; - use crate::models::torrent_file::{Torrent, TorrentInfo}; + use crate::models::torrent_file::{Torrent, TorrentInfoDictionary}; use crate::services::torrent_file::generate_random_torrent; #[test] @@ -72,7 +135,7 @@ mod tests { let torrent = generate_random_torrent(uuid); let expected_torrent = Torrent { - info: TorrentInfo { + info: TorrentInfoDictionary { name: "file-d6170378-2c14-4ccc-870d-2a8e15195e23.txt".to_string(), pieces: Some(ByteBuf::from(vec![ 62, 231, 243, 51, 234, 165, 204, 209, 51, 132, 163, 133, 249, 50, 107, 46, 24, 15, 251, 32, diff --git a/src/upgrades/from_v1_0_0_to_v2_0_0/databases/sqlite_v2_0_0.rs b/src/upgrades/from_v1_0_0_to_v2_0_0/databases/sqlite_v2_0_0.rs index f0315ff2..f5a0204c 100644 --- a/src/upgrades/from_v1_0_0_to_v2_0_0/databases/sqlite_v2_0_0.rs +++ b/src/upgrades/from_v1_0_0_to_v2_0_0/databases/sqlite_v2_0_0.rs @@ -7,7 +7,7 @@ use sqlx::{query, query_as, SqlitePool}; use super::sqlite_v1_0_0::{TorrentRecordV1, UserRecordV1}; use crate::databases::database::{self, TABLES_TO_TRUNCATE}; -use crate::models::torrent_file::{TorrentFile, TorrentInfo}; +use crate::models::torrent_file::{TorrentFile, TorrentInfoDictionary}; #[derive(Debug, Serialize, Deserialize, sqlx::FromRow)] pub struct CategoryRecordV2 { @@ -32,7 +32,7 @@ pub struct TorrentRecordV2 { impl TorrentRecordV2 { #[must_use] - pub fn from_v1_data(torrent: &TorrentRecordV1, torrent_info: &TorrentInfo, uploader: &UserRecordV1) -> Self { + pub fn from_v1_data(torrent: &TorrentRecordV1, torrent_info: &TorrentInfoDictionary, uploader: &UserRecordV1) -> Self { Self { torrent_id: torrent.torrent_id, uploader_id: uploader.user_id,