Skip to content

Commit

Permalink
refactor: skip download links duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
Kremilly committed Sep 30, 2024
1 parent 28f39b1 commit ae10e32
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/syntax/blocks/downloads_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use is_url::is_url;
use std::{
io::BufRead,
error::Error,
collections::HashSet,
};

use crate::{
Expand Down Expand Up @@ -37,6 +38,8 @@ pub struct DownloadsBlock;
impl DownloadsBlock {

async fn block(contents: &str, downloads_content: &str, path: &str, flags: &Flags) -> Result<(), Box<dyn Error>> {
let mut seen_urls = HashSet::new();

for line in downloads_content.lines() {
let url = line.trim().split_whitespace().next().unwrap_or("");
let final_url = Providers::new(url).arxiv();
Expand All @@ -47,11 +50,17 @@ impl DownloadsBlock {
break;
}

if seen_urls.contains(&final_url) {
continue;
}

seen_urls.insert(final_url.to_string());

if !Macros::handle_check_macro_line(&line, "ignore") {
if !final_url.is_empty() && is_url(&final_url) && final_url.starts_with("http") {
Tasks::download(
Some(contents),
&url,
&final_url,
&path,
flags,
).await?;
Expand Down

0 comments on commit ae10e32

Please sign in to comment.