Clean things up a bit
This commit is contained in:
parent
3f2b002f52
commit
774a5ed4ac
9 changed files with 223 additions and 172 deletions
51
src/actions/transmission/action.rs
Normal file
51
src/actions/transmission/action.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
use crate::actions::transmission::client::TransmissionClient;
|
||||
use crate::actions::transmission::config::TransmissionConfig;
|
||||
use crate::db::{Database, TransmissionProcessedTable};
|
||||
use color_eyre::eyre::Result;
|
||||
use log::{debug, info, warn};
|
||||
|
||||
/// Action for submitting magnet links to Transmission
|
||||
pub struct TransmissionAction {
|
||||
client: TransmissionClient,
|
||||
db: Database,
|
||||
}
|
||||
|
||||
impl TransmissionAction {
|
||||
pub async fn new(config: &TransmissionConfig, db: Database) -> Result<Self> {
|
||||
let client = TransmissionClient::new(config)?;
|
||||
|
||||
Ok(TransmissionAction { client, db })
|
||||
}
|
||||
|
||||
/// Process all unprocessed magnet links
|
||||
pub async fn process_unprocessed_magnets(&mut self) -> Result<usize> {
|
||||
let unprocessed_magnets = self
|
||||
.db
|
||||
.get_unprocessed_magnets_for_table::<TransmissionProcessedTable>()?;
|
||||
let mut processed_count = 0;
|
||||
|
||||
for magnet in unprocessed_magnets {
|
||||
if let Some(id) = magnet.id {
|
||||
match self.client.submit_magnet(&magnet.link).await {
|
||||
Ok(_) => {
|
||||
info!(
|
||||
"Successfully submitted magnet link to Transmission: {}",
|
||||
magnet.title
|
||||
);
|
||||
debug!("Magnet link: {}", magnet.link);
|
||||
self.db
|
||||
.mark_magnet_processed_for_table::<TransmissionProcessedTable>(id)?;
|
||||
processed_count += 1;
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to submit magnet link to Transmission: {}", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
warn!("Skipping magnet with null ID: {}", magnet.link);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(processed_count)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue