Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -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
40 changes: 20 additions & 20 deletions docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
37 changes: 17 additions & 20 deletions src/http/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<String>();
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(),
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down