Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
72bd880950
|
34
index.js
34
index.js
@@ -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) {
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
Reference in New Issue
Block a user