added SpigotMC!

Well its technically its Spiget, but same diff
This commit is contained in:
2025-12-14 00:05:09 -08:00
parent aee24d9492
commit 72bd880950
2 changed files with 36 additions and 2 deletions

View File

@@ -178,6 +178,39 @@ const handleModrinth = async (url) => {
await downloadJar(file.url, file.filename); await downloadJar(file.url, file.filename);
}; };
// --- Handle SpigotMC ---
const handleSpigotMC = async (url) => {
const match = url.match(/spigotmc\.org\/resources\/.*\.(\d+)/);
if (!match) throw new Error("Invalid SpigotMC resource URL");
const resourceId = match[1];
const resource = await axios
.get(`https://api.spiget.org/v2/resources/${resourceId}`)
.then(res => res.data);
const versionData = await axios
.get(`https://api.spiget.org/v2/resources/${resourceId}/versions/latest`)
.then(res => res.data);
const baseName = resource.name
.split("[")[0]
.trim()
.split(/\s+/)
.slice(0, 2)
.join("-");
const rawVersion = versionData?.name ?? "latest";
const version = rawVersion.replace(/^v/i, "");
const fileName = `${baseName}-${version}.jar`;
const downloadURL = `https://api.spiget.org/v2/resources/${resourceId}/download`;
console.log(`Spiget download: ${downloadURL}`);
await downloadJar(downloadURL, fileName);
};
// --- Handle Direct (Mainly for Floodgate) --- // --- Handle Direct (Mainly for Floodgate) ---
const handleDirect = async (url) => { const handleDirect = async (url) => {
let name = path.basename(url.split("?")[0]); let name = path.basename(url.split("?")[0]);
@@ -384,6 +417,7 @@ await Promise.all(
if (url.includes("modrinth.com")) return handleModrinth(url); if (url.includes("modrinth.com")) return handleModrinth(url);
if (url.includes("papermc.io")) return handlePaperMC(url); if (url.includes("papermc.io")) return handlePaperMC(url);
if (url.includes("dev.bukkit.org")) return handleBukkit(url); if (url.includes("dev.bukkit.org")) return handleBukkit(url);
if (url.includes("spigotmc.org")) return handleSpigotMC(url);
if (url.includes("/job/")) return handleJenkins(url); if (url.includes("/job/")) return handleJenkins(url);
if (url.endsWith(".jar") || url.includes("download.geysermc.org")) return handleDirect(url); if (url.endsWith(".jar") || url.includes("download.geysermc.org")) return handleDirect(url);
} catch (err) { } catch (err) {

View File

@@ -1,6 +1,6 @@
{ {
"name": "download-plugs", "name": "super-cool-jar-downloader",
"version": "1.1.1", "version": "1.2.0",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"run": "node index.js" "run": "node index.js"