fix: git id extraction

This commit is contained in:
Aravinth Manivannan 2023-10-20 14:21:05 +05:30
parent e057f752d7
commit f2afc141a8
Signed by untrusted user: realaravinth
GPG key ID: F8F50389936984FF

View file

@ -189,11 +189,18 @@ impl Data {
}
pub fn get_gist_id(url: &str) -> &str {
url.split('/').last().unwrap()
let mut id = url.split('/').last().unwrap();
id = if id.ends_with(".js") {
let splits: Vec<&str> = id.split(".js").collect();
splits.get(0).unwrap()
} else {
id
};
id
}
pub async fn get_gist(&self, gist_url: String) -> (String, GistContent) {
let id = Self::get_gist_id(&gist_url).to_owned();
let mut id = Self::get_gist_id(&gist_url).to_owned();
let file_name = if gist_url.contains('?') {
let parsed = url::Url::parse(&gist_url).unwrap();
if let Some((_, file_name)) = parsed.query_pairs().find(|(k, _)| k == "file") {
@ -211,6 +218,7 @@ impl Data {
const URL: &str = "https://api.github.com/gists/";
let url = format!("{}{}", URL, id);
println!("{url}");
let resp = self
.client