@@ -6,6 +6,7 @@ use std::sync::LazyLock;
66use thiserror:: Error ;
77
88use crate :: decommission:: DECOMMISSION_LIST ;
9+ use crate :: legal_block:: LEGAL_BLOCK_LIST ;
910use crate :: scraper:: process_html_index;
1011
1112#[ allow( dead_code) ]
@@ -31,6 +32,8 @@ pub enum ContentError {
3132 TooMayRequests ,
3233 #[ error( "wiki has been decommissioned" ) ]
3334 Decommissioned ,
35+ #[ error( "unavailable for legal reasons" ) ]
36+ UnavailableForLegalReasons ,
3437 #[ error( "{0}" ) ]
3538 OtherError ( String ) ,
3639}
@@ -45,6 +48,19 @@ fn repo_slug(account: &str, repository: &str) -> String {
4548 format ! ( "{account}/{repository}" )
4649}
4750
51+ fn reject_blocked_repo ( account : & str , repository : & str ) -> Result < ( ) , ContentError > {
52+ let repo = repo_slug ( account, repository) ;
53+ if LEGAL_BLOCK_LIST . contains ( repo. as_str ( ) ) {
54+ return Err ( ContentError :: UnavailableForLegalReasons ) ;
55+ }
56+
57+ if DECOMMISSION_LIST . contains ( repo. as_str ( ) ) {
58+ return Err ( ContentError :: Decommissioned ) ;
59+ }
60+
61+ Ok ( ( ) )
62+ }
63+
4864fn raw_wiki_source_url ( account : & str , repository : & str , page : & str , extension : & str ) -> String {
4965 let page_encoded =
5066 percent_encoding:: utf8_percent_encode ( page, percent_encoding:: NON_ALPHANUMERIC ) ;
@@ -93,10 +109,7 @@ pub async fn retrieve_source_file(
93109 page : & str ,
94110 client : & Client ,
95111) -> Result < Content , ContentError > {
96- // Skip decommissioned wikis
97- if DECOMMISSION_LIST . contains ( repo_slug ( account, repository) . as_str ( ) ) {
98- return Err ( ContentError :: Decommissioned ) ;
99- }
112+ reject_blocked_repo ( account, repository) ?;
100113
101114 match retrieve_source_file_extension ( account, repository, page, client, Content :: Markdown , "md" )
102115 . await
@@ -183,6 +196,8 @@ pub async fn retrieve_wiki_index(
183196 repository : & str ,
184197 client : & Client ,
185198) -> Result < Content , ContentError > {
199+ reject_blocked_repo ( account, repository) ?;
200+
186201 let html = with_rate_limit_fallback ( |domain| async move {
187202 retrieve_github_com_html ( account, repository, "" , client, domain) . await
188203 } )
@@ -208,6 +223,8 @@ pub async fn retrieve_wiki_sitemap_index(
208223 repository : & str ,
209224 client : & Client ,
210225) -> Result < String , ContentError > {
226+ reject_blocked_repo ( account, repository) ?;
227+
211228 let html = with_rate_limit_fallback ( |domain| async move {
212229 retrieve_github_com_html ( account, repository, "" , client, domain) . await
213230 } )
@@ -368,6 +385,28 @@ mod tests {
368385 assert ! ( content. is_ok( ) ) ;
369386 }
370387
388+ #[ tokio:: test]
389+ async fn legal_block_source_file ( ) {
390+ let client = Client :: new ( ) ;
391+ let content = retrieve_source_file ( "mms75" , "sfz" , "Home" , & client) . await ;
392+
393+ assert ! ( matches!(
394+ content,
395+ Err ( ContentError :: UnavailableForLegalReasons )
396+ ) ) ;
397+ }
398+
399+ #[ tokio:: test]
400+ async fn legal_block_wiki_index ( ) {
401+ let client = Client :: new ( ) ;
402+ let content = retrieve_wiki_index ( "mms75" , "sfz" , & client) . await ;
403+
404+ assert ! ( matches!(
405+ content,
406+ Err ( ContentError :: UnavailableForLegalReasons )
407+ ) ) ;
408+ }
409+
371410 #[ tokio:: test]
372411 async fn wiki_sitemap_index ( ) {
373412 let client = Client :: new ( ) ;
0 commit comments