From f291bcbb4b3ff7fd7320a44891756c5c419902ec Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Mon, 19 Apr 2021 18:47:19 +0200 Subject: [PATCH] Handle external images in forum posts --- src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index b161df7..7fa469e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -640,12 +640,15 @@ async fn process(ilias: Arc, mut path: PathBuf, obj: Object) -> Result<() for (id, image) in all_images { let src = URL::from_href(&image)?; let dl = ilias.download(&src.url).await?; - let m = image_src_regex - .captures(&image) - .context(format!("image src {} unexpected format", image))?; - let (media_id, filename) = (m.get(1).unwrap().as_str(), m.get(2).unwrap().as_str()); let mut path = path.clone(); - path.push(file_escape(&format!("{}_{}_{}", id, media_id, filename))); + if let Some(m) = image_src_regex.captures(&image) { + // image uploaded to ILIAS + let (media_id, filename) = (m.get(1).unwrap().as_str(), m.get(2).unwrap().as_str()); + path.push(file_escape(&format!("{}_{}_{}", id, media_id, filename))); + } else { + // external image + path.push(file_escape(&format!("{}_{}", id, image))); + } spawn!(handle_gracefully(async move { let bytes = dl.bytes().await?; write_file_data(&path, &mut &*bytes)