diff --git a/.gitignore b/.gitignore index ea8c4bf..5766b0d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,13 @@ -/target +### Rust ### +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb diff --git a/docker/build.sh b/docker/build.sh index a44f3a1..ecc59e9 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -3,22 +3,22 @@ set -e # Derive TARGETARCH from TARGETPLATFORM if not already set if [ -z "$TARGETARCH" ]; then - TARGETARCH=$(echo $TARGETPLATFORM | cut -d'/' -f2) + TARGETARCH=$(echo $TARGETPLATFORM | cut -d'/' -f2) fi case $TARGETARCH in - "amd64") - apt install -y musl-tools - export CARGO_BUILD_TARGET=x86_64-unknown-linux-musl - ;; - "arm64") - apt install -y g++-aarch64-linux-gnu libc6-dev-arm64-cross - export CARGO_BUILD_TARGET=aarch64-unknown-linux-gnu - ;; - *) - echo "Unsupported architecture: $TARGETARCH" - exit 1 - ;; +"amd64") + apt install -y musl-tools + export CARGO_BUILD_TARGET=x86_64-unknown-linux-musl + ;; +"arm64") + apt install -y g++-aarch64-linux-gnu libc6-dev-arm64-cross + export CARGO_BUILD_TARGET=aarch64-unknown-linux-gnu + ;; +*) + echo "Unsupported architecture: $TARGETARCH" + exit 1 + ;; esac export RUSTFLAGS="-Ctarget-feature=-crt-static" @@ -27,11 +27,11 @@ rustup target add ${CARGO_BUILD_TARGET} cargo build --release --target ${CARGO_BUILD_TARGET} while getopts "c:" o; do - case "${o}" in - c) - location=${OPTARG} - file target/${CARGO_BUILD_TARGET}/release/putioarr - cp target/${CARGO_BUILD_TARGET}/release/putioarr $location - ;; - esac + case "${o}" in + c) + location=${OPTARG} + file target/${CARGO_BUILD_TARGET}/release/putioarr + cp target/${CARGO_BUILD_TARGET}/release/putioarr $location + ;; + esac done diff --git a/src/http/handlers.rs b/src/http/handlers.rs index 3fa462b..2eab2fd 100644 --- a/src/http/handlers.rs +++ b/src/http/handlers.rs @@ -2,7 +2,7 @@ use crate::{ // downloader::DownloadStatus, services::putio::{self, PutIOTransfer}, services::transmission::{TransmissionRequest, TransmissionTorrent}, - AppData, ArrConfig, Config, + AppData, Config, }; use actix_web::web; use anyhow::Result; @@ -67,22 +67,18 @@ pub(crate) async fn handle_torrent_add( Ok(t) => { // Store transfer state with the torrent hash // When put.io processes this torrent, it will have the same hash - if let Ok(hash_bytes) = t.info_hash() { - // Convert bytes to hex string manually - let hash = hash_bytes.iter() - .map(|byte| format!("{:02x}", byte)) - .collect::(); - let full_download_dir = if category != "default" { - format!("{}/{}", app_data.config.download_directory, category) - } else { - app_data.config.download_directory.clone() - }; - app_data.state.add_transfer( - hash.to_lowercase(), - category.clone(), - full_download_dir - ).await?; - } + // The info_hash() returns the hash as a String in hex format + let hash = t.info_hash(); + let full_download_dir = if category != "default" { + format!("{}/{}", app_data.config.download_directory, category) + } else { + app_data.config.download_directory.clone() + }; + app_data.state.add_transfer( + hash.to_lowercase(), + category.clone(), + full_download_dir + ).await?; info!( "{}: torrent uploaded (category: {})", format!("[ffff: {}]", t.name).magenta(), @@ -181,11 +177,12 @@ pub(crate) async fn handle_torrent_get( let transmission_transfers = transfers.into_iter().map(|t| { let app_data = app_data.clone(); async move { - let mut tt: TransmissionTorrent = t.clone().into(); + let hash = t.hash.clone(); + let mut tt: TransmissionTorrent = t.into(); // Get the correct download directory from state if available - if let Some(hash) = &t.hash { + if let Some(h) = &hash { tt.download_dir = app_data.state.get_download_dir_for_transfer( - hash, + h, &app_data.config.download_directory ).await; } else { diff --git a/src/state.rs b/src/state.rs index 59d010e..a58456b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,7 +1,6 @@ use anyhow::Result; use serde::{Deserialize, Serialize}; use std::collections::HashMap; -use std::path::PathBuf; use std::sync::Arc; use tokio::sync::RwLock;