aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-06 19:53:51 -0700
committerFuwn <[email protected]>2021-05-06 19:53:51 -0700
commit24c158a62014d0c8fd54f85415c291e94be57a3d (patch)
tree638c32d9e3a4639930318435f374ce43a748e47c
parentfix(structures): remove random create pub (diff)
downloadapi-24c158a62014d0c8fd54f85415c291e94be57a3d.tar.xz
api-24c158a62014d0c8fd54f85415c291e94be57a3d.zip
fix(utils): no timeout on request, implements safe guards against rate-limiting
-rw-r--r--src/structures.rs10
-rw-r--r--src/utils.rs6
2 files changed, 13 insertions, 3 deletions
diff --git a/src/structures.rs b/src/structures.rs
index 13f904d..0e9f227 100644
--- a/src/structures.rs
+++ b/src/structures.rs
@@ -10,6 +10,16 @@ pub struct GitHubAPIResponse {
pub tree: Vec<GitHubAPIResponseTree>,
pub truncated: bool,
}
+impl Default for GitHubAPIResponse {
+ fn default() -> Self {
+ GitHubAPIResponse {
+ sha: "rate limited".to_string(),
+ url: "rate limited".to_string(),
+ tree: vec![],
+ truncated: false,
+ }
+ }
+}
#[derive(Serialize, Deserialize, Debug)]
pub struct GitHubAPIResponseTree {
diff --git a/src/utils.rs b/src/utils.rs
index bf10d71..b4672e0 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -18,9 +18,9 @@ pub async fn github_api() -> Result<GitHubAPIResponse, Box<dyn std::error::Error
std::env::var("GITHUB_TOKEN").unwrap_or_else(|_| "Null".to_string())
),
)
+ .timeout(std::time::Duration::from_secs(60))
.send()
- .await
- .unwrap()
+ .await?
.json::<GitHubAPIResponse>()
.limit(20_000_000)
.await
@@ -31,7 +31,7 @@ pub async fn github_api() -> Result<GitHubAPIResponse, Box<dyn std::error::Error
pub async fn filter_languages() -> Vec<String> {
let mut languages = vec![];
- for i in github_api().await.unwrap().tree {
+ for i in github_api().await.unwrap_or_default().tree {
if i._type == "tree" {
languages.push(i.path);
}