Fix SpigotMC plugin downloads by using direct URLs

This commit is contained in:
Rbanh committed 2025-03-30 19:52:47 -04:00
1 parent 1ebb16c15f
commit a5e7b766ac
2 files changed
+51 -11

No files matched your search

+29 -10
View File
@@ -352,20 +352,39 @@ impl Repository for SpigotMCCrawler {
}
async fn download_plugin(&self, plugin_id: &str, version: &str, destination: &Path) -> Result<String, String> {
// Going with Option 1: Download latest version associated with the resource ID
// First, get the plugin details
let details = self.get_plugin_details(plugin_id).await?;
let download_url = &details.download_url;
if download_url.is_empty() {
return Err(format!("No download URL found for SpigotMC resource {}", plugin_id));
}
// Use the SpigotMC direct download URL instead of SpiGet
// SpigotMC has a direct download URL pattern for resources
let direct_download_url = format!("https://www.spigotmc.org/resources/{}/download", plugin_id);
// We ignore the 'version' parameter here because SpiGet usually only provides the latest download
println!("Warning: SpigotMC download via SpiGet usually fetches the LATEST version, requested version '{}' might be ignored.", version);
// Log the download attempt
println!("Attempting to download plugin from SpigotMC direct URL: {}", direct_download_url);
println!("Requested version: {} (Note: SpigotMC usually provides latest version only)", version);
match self.client.download(download_url, destination).await {
Ok(_) => Ok(destination.to_string_lossy().to_string()), // Restore returning path
Err(e) => Err(format!("Failed to download from SpiGet: {}", e))
// Try to download using direct SpigotMC URL
match self.client.download(&direct_download_url, destination).await {
Ok(_) => {
println!("Successfully downloaded plugin from SpigotMC direct URL");
Ok(destination.to_string_lossy().to_string())
},
Err(e) => {
// If direct download fails, try the SpiGet URL as fallback
println!("Direct SpigotMC download failed: {}. Trying SpiGet URL as fallback...", e);
let download_url = &details.download_url;
if download_url.is_empty() {
return Err(format!("No download URL found for SpigotMC resource {}", plugin_id));
}
println!("Falling back to SpiGet download URL: {}", download_url);
match self.client.download(download_url, destination).await {
Ok(_) => Ok(destination.to_string_lossy().to_string()),
Err(e) => Err(format!("Failed to download from SpiGet: {}", e))
}
}
}
}
}