feat(api): remove a release from the blacklist (#283)
ci / web (push) Successful in 28s
e2e / e2e (push) Successful in 1m54s
ci / rust (push) Successful in 2m16s
ci / image (push) Successful in 2m12s

This commit was merged in pull request #283.
This commit is contained in:
2026-11-15 15:15:04 +00:00
parent 9adbca3acd
commit 3faa6ea8aa
6 changed files with 183 additions and 1 deletions
+112
View File
@@ -0,0 +1,112 @@
//! Manual removal from the release blacklist (`DESIGN.md` §6.3).
use axum::extract::{Query, State};
use axum::http::StatusCode;
use serde::Deserialize;
use utoipa::IntoParams;
use crate::movies::{pool, ApiError, ErrorBody};
use crate::state::AppState;
#[derive(Debug, Deserialize, IntoParams)]
pub struct RemoveQuery {
/// The blacklisted torrent's v1 infohash, any case.
pub infohash: String,
}
/// Un-blacklist one release, by both its infohash and its normalised name.
/// The operator's override for a hard fail that should not have been one.
#[utoipa::path(
delete, path = "/api/blacklist", tag = "blacklist",
params(RemoveQuery),
responses(
(status = 204),
(status = 404, body = ErrorBody),
(status = 500, body = ErrorBody),
(status = 503, body = ErrorBody)
)
)]
pub async fn remove(
State(state): State<AppState>,
Query(query): Query<RemoveQuery>,
) -> Result<StatusCode, ApiError> {
let removed = arr_db::blacklist::remove(pool(&state)?, &query.infohash).await?;
if removed == 0 {
return Err(ApiError::BlacklistEntryNotFound);
}
tracing::info!(
infohash = query.infohash,
removed,
"blacklist entry removed by hand"
);
Ok(StatusCode::NO_CONTENT)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{router, Upstreams};
const HASH: &str = "72be1ef095cacd4edece29c28b3d3b36f4fafa1d";
async fn application() -> (tempfile::TempDir, AppState, String) {
let dir = tempfile::tempdir().expect("tempdir");
let database = arr_db::Db::connect(dir.path().join("arr.db"))
.await
.expect("connect database");
database.migrate().await.expect("migrate database");
let state = AppState::new(Upstreams::new(
"http://127.0.0.1:1".into(),
"http://127.0.0.1:1".into(),
))
.expect("state")
.with_database(database);
let listener = tokio::net::TcpListener::bind("127.0.0.1:0")
.await
.expect("bind");
let address = listener.local_addr().expect("address");
let app = router(state.clone());
tokio::spawn(async move { axum::serve(listener, app).await.expect("serve") });
(dir, state, format!("http://{address}"))
}
async fn delete(base: &str, infohash: &str) -> StatusCode {
reqwest::Client::new()
.delete(format!("{base}/api/blacklist?infohash={infohash}"))
.send()
.await
.expect("delete")
.status()
}
#[tokio::test]
async fn deleting_a_blacklisted_infohash_unblocks_it() {
let (_dir, state, base) = application().await;
let database = state.database().expect("database");
arr_db::blacklist::add(
database.pool(),
Some(HASH),
"Silo.S03.2160p.ATVP.WEB-DL.DDP5.1.H.265-NTb",
"required_audio",
)
.await
.expect("blacklist");
assert_eq!(
delete(&base, &HASH.to_ascii_uppercase()).await,
StatusCode::NO_CONTENT
);
let blacklist = arr_db::Blacklist::load(database.pool())
.await
.expect("load");
assert!(!blacklist.blocks_infohash(HASH));
assert!(!blacklist.blocks_name("Silo.S03.2160p.ATVP.WEB-DL.DDP5.1.H.265-NTb"));
}
#[tokio::test]
async fn deleting_an_unknown_infohash_is_not_found() {
let (_dir, _state, base) = application().await;
assert_eq!(delete(&base, HASH).await, StatusCode::NOT_FOUND);
}
}
+2
View File
@@ -6,6 +6,7 @@
//! carrying a `#[utoipa::path]` annotation. A handler added without one fails
//! to compile, and the gate in DESIGN.md §12 fails with it.
mod blacklist;
mod downloads;
mod health;
pub mod jellyfin;
@@ -97,6 +98,7 @@ fn api_router() -> OpenApiRouter<AppState> {
OpenApiRouter::with_openapi(ApiDoc::openapi())
.routes(routes!(health::health))
.routes(routes!(downloads::list))
.routes(routes!(blacklist::remove))
.routes(routes!(movies::list, movies::create))
.routes(routes!(movies::get, movies::update, movies::delete))
.routes(routes!(movies::search))
+6
View File
@@ -196,6 +196,7 @@ pub enum ApiError {
OwnerNotFound,
PolicyNotFound,
RootNotFound,
BlacklistEntryNotFound,
/// A `media_files` row that is not there. Named apart from
/// [`Self::NotFound`] because the subtitle surface (§15) is keyed on
/// files, not on titles, and "movie not found" would misdirect.
@@ -244,6 +245,11 @@ impl IntoResponse for ApiError {
Self::OwnerNotFound => (StatusCode::NOT_FOUND, "owner not found".to_string(), None),
Self::PolicyNotFound => (StatusCode::NOT_FOUND, "policy not found".to_string(), None),
Self::RootNotFound => (StatusCode::NOT_FOUND, "root not found".to_string(), None),
Self::BlacklistEntryNotFound => (
StatusCode::NOT_FOUND,
"no blacklist entry for that infohash".to_string(),
None,
),
Self::MediaFileNotFound => (
StatusCode::NOT_FOUND,
"media file not found".to_string(),