Merge branch 'imdb' into 'main'
Add optional imdb_id See merge request kernald/reddit-magnet!9
This commit is contained in:
commit
8eda807ead
7 changed files with 14 additions and 0 deletions
1
migrations/2025-05-01-103700_add_imdb_id/down.sql
Normal file
1
migrations/2025-05-01-103700_add_imdb_id/down.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE magnets DROP COLUMN imdb_id;
|
||||
2
migrations/2025-05-01-103700_add_imdb_id/up.sql
Normal file
2
migrations/2025-05-01-103700_add_imdb_id/up.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE magnets
|
||||
ADD imdb_id VARCHAR;
|
||||
|
|
@ -18,6 +18,7 @@ use std::path::{Path, PathBuf};
|
|||
pub struct SourceConfig {
|
||||
pub username: String,
|
||||
pub title_filter: Option<String>,
|
||||
pub imdb_id: Option<String>,
|
||||
}
|
||||
|
||||
/// Main application configuration
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ impl Database {
|
|||
subreddit: post.subreddit.as_str(),
|
||||
link: m,
|
||||
published_at: &published_at,
|
||||
imdb_id: post.imdb_id.as_deref(),
|
||||
})
|
||||
.collect::<Vec<NewMagnet>>();
|
||||
|
||||
|
|
@ -167,6 +168,7 @@ mod tests {
|
|||
"magnet:?xt=urn:btih:test2".to_string(),
|
||||
],
|
||||
timestamp: Utc::now(),
|
||||
imdb_id: None,
|
||||
};
|
||||
let expected_timestamp = post_info.timestamp.naive_utc();
|
||||
|
||||
|
|
@ -205,6 +207,7 @@ mod tests {
|
|||
"magnet:?xt=urn:btih:test2".to_string(),
|
||||
],
|
||||
timestamp: Utc::now(),
|
||||
imdb_id: None,
|
||||
};
|
||||
|
||||
// First insertion should succeed and insert 2 links
|
||||
|
|
@ -222,6 +225,7 @@ mod tests {
|
|||
"magnet:?xt=urn:btih:test3".to_string(), // New
|
||||
],
|
||||
timestamp: Utc::now(),
|
||||
imdb_id: Some("tt1234567".to_string()),
|
||||
};
|
||||
|
||||
// Second insertion should succeed but only insert the new link
|
||||
|
|
@ -243,6 +247,7 @@ mod tests {
|
|||
"magnet:?xt=urn:btih:test2".to_string(), // Duplicate
|
||||
],
|
||||
timestamp: Utc::now(),
|
||||
imdb_id: None,
|
||||
};
|
||||
|
||||
// Third insertion should succeed but insert 0 links
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ struct PostInfo {
|
|||
magnet_links: Vec<Magnet>,
|
||||
subreddit: String,
|
||||
timestamp: DateTime<Utc>,
|
||||
imdb_id: Option<String>,
|
||||
}
|
||||
|
||||
/// Filters posts based on a title filter pattern
|
||||
|
|
@ -112,6 +113,7 @@ async fn main() -> Result<()> {
|
|||
subreddit: subreddit.to_string(),
|
||||
magnet_links,
|
||||
timestamp: post.created,
|
||||
imdb_id: source_config.imdb_id.clone(),
|
||||
};
|
||||
|
||||
// Store the post info in the database
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ pub struct Magnet {
|
|||
pub subreddit: String,
|
||||
pub link: String,
|
||||
pub published_at: NaiveDateTime,
|
||||
pub imdb_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
|
|
@ -23,6 +24,7 @@ pub struct NewMagnet<'a> {
|
|||
pub subreddit: &'a str,
|
||||
pub link: &'a str,
|
||||
pub published_at: &'a NaiveDateTime,
|
||||
pub imdb_id: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Queryable, Selectable)]
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ diesel::table! {
|
|||
subreddit -> Text,
|
||||
link -> Text,
|
||||
published_at -> Timestamp,
|
||||
imdb_id -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue