Repository: mediar-ai/screenpipe
File: screenpipe-core/src/pipes.rs (Rust)

Code before:
    pub fn stop(&self) {
        let _ = self.shutdown.send(true);
    }
}

static CRON_HANDLES: Lazy<tokio::sync::Mutex<HashMap<String, Vec<CronHandle>>>> =
    Lazy::new(|| tokio::sync::Mutex::new(HashMap::new()));

// Add this function to generate a secure cron secret
fn generate_cron_secret() -> String {
    thread_rng()
        .sample_iter(&Alphanumeric)
        .take(32)
        .map(char::from)
        .collect()
}

// Update this function near the top of the file
fn sanitize_pipe_name(name: &str) -> String {
    // First check if this is a GitHub URL and extract the repo name
    if let Ok(url) = Url::parse(name) {
        if url.host_str() == Some("github.com") {
            let path_segments: Vec<&str> = url.path_segments().unwrap().collect();
            if path_segments.len() >= 2 {
                if let Some(tree_index) = path_segments.iter().position(|&s| s == "tree") {
                    let remaining_segments = &path_segments[tree_index + 1..];
                    if remaining_segments.len() > 2 {
                        debug!("Using repository name for pipe: {:?}", remaining_segments);
                        return remaining_segments.last().unwrap().to_string();
                    } else {
                        debug!("Using repository name for pipe: {:?}", path_segments[1]);
                        return path_segments[1].to_string();
                    }
                } else {
                    debug!("Using repository name for pipe: {:?}", path_segments[1]);
                    return path_segments[1].to_string();
                }
            }
        }
    }

    // Fall back to original sanitization logic for non-GitHub URLs
    let re = Regex::new(r"[^a-zA-Z0-9_-]").unwrap();
    let sanitized = re.replace_all(name, "-").to_string();

    // Remove "-ref-main/" suffix if it exists
    sanitized
        .strip_suffix("-ref-main/")
        .or_else(|| sanitized.strip_suffix("-ref-main"))
        .unwrap_or(&sanitized)
        .to_string()

Review comment (suggestion):
here the repo_name is hardcode to second segment, that's why downloading pipes from these urls `https://github.com/mediar-ai/screenpipe/tree/main/pipes/search` were downloadings file to `~/.screenpipe/screenpipe` dir

https://github.com/mediar-ai/screenpipe/issues/1533#issuecomment-2699970235

Code after:
    pub fn stop(&self) {
        let _ = self.shutdown.send(true);
    }
}

static CRON_HANDLES: Lazy<tokio::sync::Mutex<HashMap<String, Vec<CronHandle>>>> =
    Lazy::new(|| tokio::sync::Mutex::new(HashMap::new()));

// Add this function to generate a secure cron secret
fn generate_cron_secret() -> String {
    thread_rng()
        .sample_iter(&Alphanumeric)
        .take(32)
        .map(char::from)
        .collect()
}

// Update this function near the top of the file
pub fn sanitize_pipe_name(name: &str) -> String {
    // First check if this is a GitHub URL and extract the repo name
    if let Ok(url) = Url::parse(name) {
        if url.host_str() == Some("github.com") {
            let path_segments: Vec<&str> = url.path_segments().unwrap().collect();
            if path_segments.len() >= 2 {
                if let Some(tree_index) = path_segments.iter().position(|&s| s == "tree") {
                    let remaining_segments = &path_segments[tree_index + 1..];
                    if remaining_segments.len() > 2 {
                        debug!("Using repository name for pipe: {:?}", 
                            remaining_segments.last().unwrap().to_string()
                        );
                        return remaining_segments.last().unwrap().to_string();
                    } else {
                        debug!("Using repository name for pipe: {:?}", path_segments[1]);
                        return path_segments[1].to_string();
                    }
                } else {
                    debug!("Using repository name for pipe: {:?}", path_segments[1]);
                    return path_segments[1].to_string();
                }
            }
        }
    }

    if Path::new(name).is_dir() {
        if let Some(basename) = Path::new(name).file_name() {
            return basename.to_string_lossy().to_string();
        }
    }

    // Fall back to original sanitization logic for non-GitHub URLs
    let re = Regex::new(r"[^a-zA-Z0-9_-]").unwrap();