Skip to content

Commit

Permalink
Merge pull request #42 from Power2All/v4.0.2
Browse files Browse the repository at this point in the history
V4.0.2
  • Loading branch information
Power2All authored Oct 21, 2024
2 parents 8876d2d + 8f59500 commit 9c1b33b
Show file tree
Hide file tree
Showing 48 changed files with 2,786 additions and 1,771 deletions.
57 changes: 27 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "torrust-actix"
version = "4.0.1"
version = "4.0.2"
edition = "2021"
license = "AGPL-3.0"
authors = [
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ Swagger UI is introduced, and when enabled in the configuration, is accessible t

### ChangeLog

#### v4.0.2
* Added option that the system will remove data from database.
* Added updates variables for the white/black list and keys tables.
* Renaming the "database" naming which should be "tables".
* A lot of fixes and bugs I stumbled upon.

#### v4.0.0
* Completely rebuilt of the tracker code, for readability.
* Moved to Actix v4, thus versioning this software to v4.0.0 as well.
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM rust:alpine

RUN apk add git musl-dev curl
RUN git clone https://github.com/Power2All/torrust-actix.git /tmp/torrust-actix
RUN cd /tmp/torrust-actix && git checkout tags/v4.0.1
RUN cd /tmp/torrust-actix && git checkout tags/v4.0.2
WORKDIR /tmp/torrust-actix
RUN cd /tmp/torrust-actix
RUN cargo build --release && rm -Rf target/release/.fingerprint target/release/build target/release/deps target/release/examples target/release/incremental
Expand Down
82 changes: 53 additions & 29 deletions src/api/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,44 +49,68 @@ pub fn api_service_routes(data: Arc<ApiServiceData>) -> Box<dyn Fn(&mut ServiceC
);

// Torrents API Routing
cfg.service(web::resource("api/torrent/{info_hash}").route(web::get().to(api_service_torrent_get)));
cfg.service(web::resource("api/torrents").route(web::get().to(api_service_torrents_get)));
cfg.service(web::resource("api/torrent/{info_hash}")
.route(web::get().to(api_service_torrent_get))
.route(web::delete().to(api_service_torrent_delete))
);
cfg.service(web::resource("api/torrent/{info_hash}/{completed}").route(web::post().to(api_service_torrent_post)));
cfg.service(web::resource("api/torrents").route(web::post().to(api_service_torrents_post)));
cfg.service(web::resource("api/torrent/{info_hash}").route(web::delete().to(api_service_torrent_delete)));
cfg.service(web::resource("api/torrents").route(web::delete().to(api_service_torrents_delete)));
cfg.service(web::resource("api/torrents")
.route(web::get().to(api_service_torrents_get))
.route(web::post().to(api_service_torrents_post))
.route(web::delete().to(api_service_torrents_delete))
);

// Whitelist API Routing
cfg.service(web::resource("api/whitelist/{info_hash}").route(web::get().to(api_service_whitelist_get)));
cfg.service(web::resource("api/whitelists").route(web::get().to(api_service_whitelists_get)));
cfg.service(web::resource("api/whitelist/{info_hash}").route(web::post().to(api_service_whitelist_post)));
cfg.service(web::resource("api/whitelists").route(web::post().to(api_service_whitelists_post)));
cfg.service(web::resource("api/whitelist/{info_hash}").route(web::delete().to(api_service_whitelist_delete)));
cfg.service(web::resource("api/whitelists").route(web::delete().to(api_service_whitelists_delete)));
cfg.service(web::resource("api/whitelist/{info_hash}")
.route(web::get().to(api_service_whitelist_get))
.route(web::post().to(api_service_whitelist_post))
.route(web::delete().to(api_service_whitelist_delete))
);
cfg.service(web::resource("api/whitelists")
.route(web::get().to(api_service_whitelists_get))
.route(web::post().to(api_service_whitelists_post))
.route(web::delete().to(api_service_whitelists_delete))
);

// Blacklist API Routing
cfg.service(web::resource("api/blacklist/{info_hash}").route(web::get().to(api_service_blacklist_get)));
cfg.service(web::resource("api/blacklists").route(web::get().to(api_service_blacklists_get)));
cfg.service(web::resource("api/blacklist/{info_hash}").route(web::post().to(api_service_blacklist_post)));
cfg.service(web::resource("api/blacklists").route(web::post().to(api_service_blacklists_post)));
cfg.service(web::resource("api/blacklist/{info_hash}").route(web::delete().to(api_service_blacklist_delete)));
cfg.service(web::resource("api/blacklists").route(web::delete().to(api_service_blacklists_delete)));
cfg.service(web::resource("api/blacklist/{info_hash}")
.route(web::get().to(api_service_blacklist_get))
.route(web::post().to(api_service_blacklist_post))
.route(web::delete().to(api_service_blacklist_delete))
);
cfg.service(web::resource("api/blacklists")
.route(web::get().to(api_service_blacklists_get))
.route(web::post().to(api_service_blacklists_post))
.route(web::delete().to(api_service_blacklists_delete))
);

// Keys API Routing
cfg.service(web::resource("api/key/{key_hash}").route(web::get().to(api_service_key_get)));
cfg.service(web::resource("api/keys").route(web::get().to(api_service_keys_get)));
cfg.service(web::resource("api/key/{key_hash}/{timeout}").route(web::post().to(api_service_key_post)));
cfg.service(web::resource("api/keys").route(web::post().to(api_service_keys_post)));
cfg.service(web::resource("api/key/{info_hash}").route(web::delete().to(api_service_key_delete)));
cfg.service(web::resource("api/keys").route(web::delete().to(api_service_keys_delete)));
cfg.service(web::resource("api/key/{key_hash}")
.route(web::get().to(api_service_key_get))
.route(web::delete().to(api_service_key_delete))
);
cfg.service(web::resource("api/key/{key_hash}/{timeout}")
.route(web::post().to(api_service_key_post))
);
cfg.service(web::resource("api/keys")
.route(web::get().to(api_service_keys_get))
.route(web::post().to(api_service_keys_post))
.route(web::delete().to(api_service_keys_delete))
);

// Users API Routing (SHA1 ID/UUID hashed key)
cfg.service(web::resource("api/user/{id}").route(web::get().to(api_service_user_get)));
cfg.service(web::resource("api/users").route(web::get().to(api_service_users_get)));
cfg.service(web::resource("api/user/{id}/{key}/{uploaded}/{downloaded}/{completed}/{updated}/{active}").route(web::post().to(api_service_user_post)));
cfg.service(web::resource("api/keys").route(web::post().to(api_service_users_post)));
cfg.service(web::resource("api/key/{info_hash}").route(web::delete().to(api_service_user_delete)));
cfg.service(web::resource("api/keys").route(web::delete().to(api_service_users_delete)));
cfg.service(web::resource("api/user/{id}")
.route(web::get().to(api_service_user_get))
.route(web::delete().to(api_service_user_delete))
);
cfg.service(web::resource("api/user/{id}/{key}/{uploaded}/{downloaded}/{completed}/{updated}/{active}")
.route(web::post().to(api_service_user_post))
);
cfg.service(web::resource("api/users")
.route(web::get().to(api_service_users_get))
.route(web::post().to(api_service_users_post))
.route(web::delete().to(api_service_users_delete))
);

// Swagger UI Routing
if data.torrent_tracker.config.tracker_config.clone().unwrap().swagger.unwrap_or(false) {
Expand Down
17 changes: 17 additions & 0 deletions src/api/api_blacklists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::api::api::{api_parse_body, api_service_token, api_validation};
use crate::api::structs::api_service_data::ApiServiceData;
use crate::api::structs::query_token::QueryToken;
use crate::common::common::hex2bin;
use crate::tracker::enums::updates_action::UpdatesAction;
use crate::tracker::structs::info_hash::InfoHash;

pub async fn api_service_blacklist_get(request: HttpRequest, path: web::Path<String>, data: Data<Arc<ApiServiceData>>) -> HttpResponse
Expand Down Expand Up @@ -88,6 +89,10 @@ pub async fn api_service_blacklist_post(request: HttpRequest, path: web::Path<St
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid info_hash {}", info)})); }
};

if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_blacklist_update(info_hash, UpdatesAction::Add);
}

return match data.torrent_tracker.add_blacklist(info_hash) {
true => { HttpResponse::Ok().content_type(ContentType::json()).json(json!({"status": "ok"})) }
false => { HttpResponse::NotModified().content_type(ContentType::json()).json(json!({"status": format!("info_hash updated {}", info)})) }
Expand Down Expand Up @@ -124,6 +129,10 @@ pub async fn api_service_blacklists_post(request: HttpRequest, payload: web::Pay
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid info_hash {}", info)})) }
};

if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_blacklist_update(info_hash, UpdatesAction::Add);
}

match data.torrent_tracker.add_blacklist(info_hash) {
true => { blacklists_output.insert(info_hash, json!({"status": "ok"})); }
false => { blacklists_output.insert(info_hash, json!({"status": "info_hash updated"})); }
Expand Down Expand Up @@ -153,6 +162,10 @@ pub async fn api_service_blacklist_delete(request: HttpRequest, path: web::Path<
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid info_hash {}", info)})); }
};

if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_blacklist_update(info_hash, UpdatesAction::Remove);
}

return match data.torrent_tracker.remove_blacklist(info_hash) {
true => { HttpResponse::Ok().content_type(ContentType::json()).json(json!({"status": "ok"})) }
false => { HttpResponse::NotModified().content_type(ContentType::json()).json(json!({"status": format!("unknown info_hash {}", info)})) }
Expand Down Expand Up @@ -189,6 +202,10 @@ pub async fn api_service_blacklists_delete(request: HttpRequest, payload: web::P
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid info_hash {}", info)})) }
};

if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_blacklist_update(info_hash, UpdatesAction::Remove);
}

match data.torrent_tracker.remove_blacklist(info_hash) {
true => { blacklists_output.insert(info_hash, json!({"status": "ok"})); }
false => { blacklists_output.insert(info_hash, json!({"status": "unknown info_hash"})); }
Expand Down
Loading

0 comments on commit 9c1b33b

Please sign in to comment.