mc-cluster/mc-cluster-image/get_latest_fabric_version.js
2024-12-06 05:52:08 -05:00

49 lines
1.7 KiB
JavaScript

const axios = require('axios');
// Function to get the latest Fabric download URL
async function getLatestFabricDownloadURL(gameVersion) {
try {
// Fetch the loader versions for the given game version
const loaderResponse = await axios.get(`https://meta.fabricmc.net/v2/versions/loader/${gameVersion}`);
const loaderVersions = loaderResponse.data;
if (loaderVersions.length === 0) {
throw new Error('No loader versions found for this game version');
}
// Get the latest loader version details (assuming the first is the latest)
const latestLoader = loaderVersions[0].loader.version;
// Fetch the installer versions
const installerResponse = await axios.get('https://meta.fabricmc.net/v2/versions/installer');
const installerVersions = installerResponse.data;
if (installerVersions.length === 0) {
throw new Error('No installer versions found');
}
// Get the latest installer version (assuming the first is the latest)
const latestInstaller = installerVersions[0].version;
// Construct the download URL
const downloadURL = `https://meta.fabricmc.net/v2/versions/loader/${gameVersion}/${latestLoader}/${latestInstaller}/server/jar`;
console.log(downloadURL);
return downloadURL;
} catch (error) {
console.error('Error fetching Fabric versions:', error.message);
}
}
// Retrieve the game version from command line arguments
const gameVersion = process.argv[2];
// Check if game version is provided
if (!gameVersion) {
console.error('Please provide a game version as an argument');
process.exit(1);
}
// Call the function with the provided game version
getLatestFabricDownloadURL(gameVersion);