Skip to main content

opensession_core/
git_storage.rs

1/// Generate a raw content URL from the git remote and file path.
2pub fn generate_raw_url(remote_url: &str, rel_path: &str) -> String {
3    // Normalize remote URL to extract owner/repo
4    let normalized = remote_url
5        .trim_end_matches(".git")
6        .replace("git@github.com:", "https://github.com/")
7        .replace("git@gitlab.com:", "https://gitlab.com/");
8
9    if normalized.contains("github.com") {
10        // https://raw.githubusercontent.com/{owner}/{repo}/opensession/{path}
11        let path = normalized.trim_start_matches("https://github.com/");
12        format!(
13            "https://raw.githubusercontent.com/{}/opensession/{}",
14            path, rel_path
15        )
16    } else if normalized.contains("gitlab.com") {
17        // https://gitlab.com/{owner}/{repo}/-/raw/opensession/{path}
18        let path = normalized.trim_start_matches("https://gitlab.com/");
19        format!("https://gitlab.com/{}/-/raw/opensession/{}", path, rel_path)
20    } else {
21        // Fallback: just use the remote URL as base
22        format!("{}/raw/opensession/{}", normalized, rel_path)
23    }
24}