Skip to content

Commit

Permalink
update logic to use new format
Browse files Browse the repository at this point in the history
  • Loading branch information
antonok-edm committed Apr 13, 2023
1 parent b769876 commit 84bae99
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions tests/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,21 @@ fn load_requests() -> Vec<RequestRuleMatch> {
reqs
}

/// Describes an online source of adblock rules.
/// Describes an entry from Brave's catalog of adblock lists.
/// https://github.com/brave/adblock-resources#filter-list-description-format
#[derive(serde::Deserialize, Debug)]
pub struct RemoteFilterCatalogEntry {
pub title: String,
pub sources: Vec<RemoteFilterSource>,
}

/// Describes an online source of adblock rules. Corresponds to a single entry of `sources` as
/// defined [here](https://github.com/brave/adblock-resources#filter-list-description-format).
#[derive(serde::Deserialize, Debug)]
pub struct RemoteFilterSource {
pub url: String,
pub title: String,
pub title: Option<String>,
pub format: adblock::lists::FilterFormat,
#[serde(default)] // should default to false if the field is missing
pub include_redirect_urls: bool,
pub support_url: String,
}

Expand All @@ -65,7 +71,7 @@ static ALL_FILTERS: once_cell::sync::Lazy<std::sync::Mutex<adblock::lists::Filte
"Downloading list of filter lists from '{}'",
DEFAULT_LISTS_URL
);
let default_lists: Vec<RemoteFilterSource> = async {
let default_catalog: Vec<RemoteFilterCatalogEntry> = async {
let body = reqwest::get(DEFAULT_LISTS_URL)
.await
.unwrap()
Expand All @@ -75,6 +81,10 @@ static ALL_FILTERS: once_cell::sync::Lazy<std::sync::Mutex<adblock::lists::Filte
serde_json::from_str(&body).unwrap()
}
.await;

assert!(default_catalog.len() == 1);
let default_lists = &default_catalog[0].sources;

println!(
"List of filter lists has {} filter lists total",
default_lists.len()
Expand Down

0 comments on commit 84bae99

Please sign in to comment.