diff --git a/index.js b/index.js index 4fb5bdb..b9b290c 100644 --- a/index.js +++ b/index.js @@ -178,6 +178,39 @@ const handleModrinth = async (url) => { 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) --- const handleDirect = async (url) => { 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("papermc.io")) return handlePaperMC(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.endsWith(".jar") || url.includes("download.geysermc.org")) return handleDirect(url); } catch (err) { diff --git a/package.json b/package.json index 40ab22c..8d06c00 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "download-plugs", - "version": "1.1.1", + "name": "super-cool-jar-downloader", + "version": "1.2.0", "main": "index.js", "scripts": { "run": "node index.js"