diff options
Diffstat (limited to 'import/src/plugins/wikimedia_commons.rs')
| -rw-r--r-- | import/src/plugins/wikimedia_commons.rs | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/import/src/plugins/wikimedia_commons.rs b/import/src/plugins/wikimedia_commons.rs index c849b61..aebf5dd 100644 --- a/import/src/plugins/wikimedia_commons.rs +++ b/import/src/plugins/wikimedia_commons.rs @@ -9,7 +9,7 @@ use crate::{ plugins::{ImportPlugin, PluginInfo}, }; use anyhow::{Context, Result}; -use jellycache::{EscapeKey, cache_store}; +use jellycache::{Cache, EscapeKey}; use reqwest::{ Client, ClientBuilder, header::{HeaderMap, HeaderName, HeaderValue}, @@ -39,27 +39,33 @@ impl WikimediaCommons { Self { client } } - pub fn image_by_filename(&self, filename: String, rt: &Handle) -> Result<String> { - cache_store( - format!("ext/wikimedia-commons/image/{}.image", EscapeKey(&filename)), - move || { - rt.block_on(async { - Ok(self - .client - .get(format!( - "https://commons.wikimedia.org/wiki/Special:FilePath/{}", - filename.replace(" ", "_") - )) - .send() - .await? - .error_for_status()? - .bytes() - .await? - .to_vec()) - }) - }, - ) - .context("mediawiki image by filename") + pub fn image_by_filename( + &self, + cache: &Cache, + filename: String, + rt: &Handle, + ) -> Result<String> { + cache + .store( + format!("ext/wikimedia-commons/image/{}.image", EscapeKey(&filename)), + move || { + rt.block_on(async { + Ok(self + .client + .get(format!( + "https://commons.wikimedia.org/wiki/Special:FilePath/{}", + filename.replace(" ", "_") + )) + .send() + .await? + .error_for_status()? + .bytes() + .await? + .to_vec()) + }) + }, + ) + .context("mediawiki image by filename") } } |