Skip to content

Commit fb338f0

Browse files
committed
fix: use MEDIA_CLIENT for GitHub fetches
1 parent 1d416fc commit fb338f0

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const ALTERNATIVE_REDDIT_URL_BASE: &str = "https://www.reddit.com";
2828
const ALTERNATIVE_REDDIT_URL_BASE_HOST: &str = "www.reddit.com";
2929

3030
pub static CLIENT: LazyLock<WreqClient> = LazyLock::new(build_client);
31+
pub static MEDIA_CLIENT: LazyLock<WreqClient> = LazyLock::new(build_client);
3132

3233
pub static OAUTH_CLIENT: LazyLock<ArcSwap<Oauth>> = LazyLock::new(|| {
3334
let client = block_on(Oauth::new());

src/main.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::sync::LazyLock;
99
use futures_lite::FutureExt;
1010
use hyper::{header::HeaderValue, Body, Request, Response};
1111
use log::{info, warn};
12-
use redlib::client::{canonical_path, proxy, rate_limit_check, CLIENT};
12+
use redlib::client::{canonical_path, proxy, rate_limit_check, MEDIA_CLIENT};
1313
use redlib::server::{self, RequestExt};
1414
use redlib::utils::{error, redirect, ThemeAssets};
1515
use redlib::{config, duplicates, headers, instance_info, post, search, settings, subreddit, user};
@@ -435,9 +435,16 @@ pub async fn proxy_commit_info() -> Result<Response<Body>, String> {
435435

436436
#[cached(time = 600)]
437437
async fn fetch_commit_info() -> String {
438-
let url = "https://github.com/redlib-org/redlib/commits/main.atom";
439-
440-
CLIENT.get(url).send().await.expect("Failed to request GitHub").text().await.expect("Failed to read body")
438+
// wreq uses http v1.x: pass URL as &str and call .send().await, then .bytes().await
439+
let bytes = MEDIA_CLIENT
440+
.get("https://github.com/redlib-org/redlib/commits/main.atom")
441+
.send()
442+
.await
443+
.expect("Failed to request GitHub")
444+
.bytes()
445+
.await
446+
.expect("Failed to read body");
447+
String::from_utf8_lossy(&bytes).into_owned()
441448
}
442449

443450
pub async fn proxy_instances() -> Result<Response<Body>, String> {
@@ -452,7 +459,14 @@ pub async fn proxy_instances() -> Result<Response<Body>, String> {
452459

453460
#[cached(time = 600)]
454461
async fn fetch_instances() -> String {
455-
let url = "https://raw.githubusercontent.com/redlib-org/redlib-instances/refs/heads/main/instances.json";
456-
457-
CLIENT.get(url).send().await.expect("Failed to request GitHub").text().await.expect("Failed to read body")
462+
// wreq uses http v1.x: pass URL as &str and call .send().await, then .bytes().await
463+
let bytes = MEDIA_CLIENT
464+
.get("https://raw.githubusercontent.com/redlib-org/redlib-instances/refs/heads/main/instances.json")
465+
.send()
466+
.await
467+
.expect("Failed to request GitHub")
468+
.bytes()
469+
.await
470+
.expect("Failed to read body");
471+
String::from_utf8_lossy(&bytes).into_owned()
458472
}

0 commit comments

Comments
 (0)