Skip to content

Commit 758bc54

Browse files
committed
fix(main): use wreq API for GitHub fetches (string URL + .send().await + .bytes())
1 parent ffd700f commit 758bc54

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

src/main.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
use cached::proc_macro::cached;
66
use clap::{Arg, ArgAction, Command};
7-
use std::str::FromStr;
87
use std::sync::LazyLock;
98

109
use futures_lite::FutureExt;
11-
use hyper::Uri;
1210
use hyper::{header::HeaderValue, Body, Request, Response};
1311
use log::{info, warn};
1412
use redlib::client::{canonical_path, proxy, rate_limit_check, CLIENT};
@@ -433,11 +431,19 @@ pub async fn proxy_commit_info() -> Result<Response<Body>, String> {
433431

434432
#[cached(time = 600)]
435433
async fn fetch_commit_info() -> String {
436-
let uri = Uri::from_str("https://github.com/redlib-org/redlib/commits/main.atom").expect("Invalid URI");
437-
438-
let resp: Body = CLIENT.get(uri).await.expect("Failed to request GitHub").into_body();
439-
440-
hyper::body::to_bytes(resp).await.expect("Failed to read body").iter().copied().map(|x| x as char).collect()
434+
// wreq uses http v1.x: pass URL as &str and call .send().await, then .bytes().await
435+
CLIENT
436+
.get("https://github.com/redlib-org/redlib/commits/main.atom")
437+
.send()
438+
.await
439+
.expect("Failed to request GitHub")
440+
.bytes()
441+
.await
442+
.expect("Failed to read body")
443+
.iter()
444+
.copied()
445+
.map(|x| x as char)
446+
.collect()
441447
}
442448

443449
pub async fn proxy_instances() -> Result<Response<Body>, String> {
@@ -452,9 +458,17 @@ pub async fn proxy_instances() -> Result<Response<Body>, String> {
452458

453459
#[cached(time = 600)]
454460
async fn fetch_instances() -> String {
455-
let uri = Uri::from_str("https://raw.githubusercontent.com/redlib-org/redlib-instances/refs/heads/main/instances.json").expect("Invalid URI");
456-
457-
let resp: Body = CLIENT.get(uri).await.expect("Failed to request GitHub").into_body();
458-
459-
hyper::body::to_bytes(resp).await.expect("Failed to read body").iter().copied().map(|x| x as char).collect()
461+
// wreq uses http v1.x: pass URL as &str and call .send().await, then .bytes().await
462+
CLIENT
463+
.get("https://raw.githubusercontent.com/redlib-org/redlib-instances/refs/heads/main/instances.json")
464+
.send()
465+
.await
466+
.expect("Failed to request GitHub")
467+
.bytes()
468+
.await
469+
.expect("Failed to read body")
470+
.iter()
471+
.copied()
472+
.map(|x| x as char)
473+
.collect()
460474
}

0 commit comments

Comments
 (0)