feat(api): remove a release from the blacklist (#283)
This commit was merged in pull request #283.
This commit is contained in:
@@ -173,6 +173,27 @@ pub async fn add(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Lift a blacklisting by hand: drop the row keyed on `infohash` and every
|
||||
/// row sharing its normalised name, so neither §6.3 key blocks the release
|
||||
/// any longer. Only the operator calls this; nothing in the grab or import
|
||||
/// path un-blacklists. Returns the number of rows removed.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// If the delete fails.
|
||||
pub async fn remove(pool: &SqlitePool, infohash: &str) -> Result<u64, sqlx::Error> {
|
||||
let infohash = infohash.to_ascii_lowercase();
|
||||
let removed = sqlx::query!(
|
||||
"DELETE FROM blacklist
|
||||
WHERE infohash = ?1
|
||||
OR normalised_name IN (SELECT normalised_name FROM blacklist WHERE infohash = ?1)",
|
||||
infohash
|
||||
)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
Ok(removed.rows_affected())
|
||||
}
|
||||
|
||||
/// The infohash a magnet link declares, lowercased.
|
||||
///
|
||||
/// Only the 40-character hex form is recognised. Base32 `btih` values exist
|
||||
@@ -193,7 +214,7 @@ pub fn magnet_infohash(download_url: &str) -> Option<String> {
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used)]
|
||||
mod tests {
|
||||
use super::{add, magnet_infohash, Blacklist};
|
||||
use super::{add, magnet_infohash, remove, Blacklist};
|
||||
use crate::Db;
|
||||
|
||||
const HASH: &str = "0123456789abcdef0123456789abcdef01234567";
|
||||
@@ -224,6 +245,31 @@ mod tests {
|
||||
assert!(!blacklist.blocks_name("Dune Part Two 2024 1080p WEB-DL"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn removing_by_infohash_clears_both_keys() {
|
||||
let (database, _dir) = database().await;
|
||||
let name = "Silo.S03.2160p.ATVP.WEB-DL.DDP5.1.H.265-NTb";
|
||||
add(database.pool(), Some(HASH), name, "required_audio")
|
||||
.await
|
||||
.unwrap();
|
||||
add(database.pool(), None, name, "required_audio")
|
||||
.await
|
||||
.unwrap();
|
||||
add(database.pool(), None, "Other.Release.2024.1080p", "size")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let removed = remove(database.pool(), &HASH.to_ascii_uppercase())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(removed, 2);
|
||||
let blacklist = Blacklist::load(database.pool()).await.unwrap();
|
||||
assert!(!blacklist.blocks_infohash(HASH));
|
||||
assert!(!blacklist.blocks_name(name));
|
||||
assert!(blacklist.blocks_name("Other.Release.2024.1080p"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_key_carries_the_reason_it_was_blacklisted_for() {
|
||||
let (database, _dir) = database().await;
|
||||
|
||||
Reference in New Issue
Block a user