Fix SpigotMC plugin downloads by using direct URLs
This commit is contained in:
1 parent
1ebb16c15f
commit
a5e7b766ac
2 files changed
+51
-11
No files matched your search
@@ -154,7 +154,22 @@ impl HttpClient {
|
||||
.build()?;
|
||||
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert(USER_AGENT, HeaderValue::from_static("PlugSnatcherApp/0.1.0"));
|
||||
headers.insert(USER_AGENT, HeaderValue::from_static("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36")); // More browser-like
|
||||
|
||||
// Add Accept header for everything
|
||||
headers.insert(ACCEPT, HeaderValue::from_static("*/*"));
|
||||
|
||||
// Add headers for better browser simulation when dealing with SpigotMC
|
||||
if url.contains("spigotmc.org") {
|
||||
headers.insert(ACCEPT, HeaderValue::from_static("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"));
|
||||
// Add custom headers as strings
|
||||
let _ = headers.insert("Sec-Fetch-Dest", HeaderValue::from_static("document"));
|
||||
let _ = headers.insert("Sec-Fetch-Mode", HeaderValue::from_static("navigate"));
|
||||
let _ = headers.insert("Sec-Fetch-Site", HeaderValue::from_static("none"));
|
||||
let _ = headers.insert("Sec-Fetch-User", HeaderValue::from_static("?1"));
|
||||
headers.insert(reqwest::header::UPGRADE_INSECURE_REQUESTS, HeaderValue::from_static("1"));
|
||||
println!("Added browser simulation headers for SpigotMC download");
|
||||
}
|
||||
|
||||
// Add GitHub token if URL is GitHub and we have a token
|
||||
if url.contains("github.com") && self.github_token.is_some() {
|
||||
@@ -166,8 +181,12 @@ impl HttpClient {
|
||||
}
|
||||
|
||||
// Get response
|
||||
println!("Sending download request to: {}", url);
|
||||
let response = client.get(url).headers(headers).send().await?;
|
||||
|
||||
// Log response status
|
||||
println!("Download response status: {}", response.status());
|
||||
|
||||
// Check if request was successful
|
||||
if !response.status().is_success() {
|
||||
return Err(format!("Failed to download: Status {}", response.status()).into());
|
||||
@@ -175,6 +194,7 @@ impl HttpClient {
|
||||
|
||||
// Get response bytes
|
||||
let bytes = response.bytes().await?;
|
||||
println!("Downloaded {} bytes", bytes.len());
|
||||
|
||||
// Create parent directories if needed
|
||||
if let Some(parent) = destination.parent() {
|
||||
@@ -185,6 +205,7 @@ impl HttpClient {
|
||||
|
||||
// Write to file
|
||||
std::fs::write(destination, bytes)?;
|
||||
println!("Successfully wrote file to: {}", destination.display());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user