Skip to content

Commit b8047ee

Browse files
Added download_url as the url not the api.github.com
1 parent 7c42cbe commit b8047ee

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

src/github/mod.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,9 +1025,10 @@ pub async fn get_readme_url_and_content(
10251025
let url =
10261026
format!("https://api.github.com/repos/{owner_name}/{repo_name}/readme?ref={branch_or_tag}");
10271027

1028-
match client
1029-
.head(&url)
1028+
let resp = match client
1029+
.get(&url)
10301030
.header("Authorization", GITHUB_KEY.to_string())
1031+
.header("Accept", "application/vnd.github.v3+json")
10311032
.header("User-Agent", "zigistry")
10321033
.send()
10331034
.await
@@ -1036,24 +1037,30 @@ pub async fn get_readme_url_and_content(
10361037
_ => return (None, None),
10371038
};
10381039

1040+
let body: serde_json::Value = match resp.json().await {
1041+
Ok(v) => v,
1042+
Err(_) => return (None, None),
1043+
};
1044+
1045+
let download_url = match body["download_url"].as_str() {
1046+
Some(u) => u.to_string(),
1047+
None => return (None, None),
1048+
};
1049+
10391050
if fetch_content {
1040-
let resp = match client
1041-
.get(&url)
1042-
.header("Accept", "application/vnd.github.v3.raw")
1051+
let content = match client
1052+
.get(&download_url)
10431053
.header("User-Agent", "zigistry")
10441054
.send()
10451055
.await
10461056
{
1047-
Ok(resp) if resp.status().is_success() => resp,
1048-
_ => return (Some(url), None),
1057+
Ok(resp) if resp.status().is_success() => resp.text().await.unwrap_or_default(),
1058+
_ => return (Some(download_url), None),
10491059
};
10501060

1051-
match resp.text().await {
1052-
Ok(content) => (Some(url), Some(content)),
1053-
Err(_) => (Some(url), None),
1054-
}
1061+
(Some(download_url), Some(content))
10551062
} else {
1056-
(Some(url), None)
1063+
(Some(download_url), None)
10571064
}
10581065
}
10591066

-9 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)