diff options
Diffstat (limited to 'lib/modrinth.js')
| -rw-r--r-- | lib/modrinth.js | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/lib/modrinth.js b/lib/modrinth.js deleted file mode 100644 index cf0f697..0000000 --- a/lib/modrinth.js +++ /dev/null @@ -1,69 +0,0 @@ -const axios = require("axios") - -const MODRINTH_API = "https://api.modrinth.com/v2" - -const GetModVersions = async slug => -{ - try - { - const response = await axios.get(`${MODRINTH_API}/project/${slug}/version`) - return response.data - } - catch (err) - { - console.error(`[Modrinth] Failed for ${slug}:`, err.message) - return null - } -} - -const GetLatestVersion = versions => -{ - if (!versions || !versions.length) - return null - return versions.sort((a, b) => new Date(b.date_published) - new Date(a.date_published))[0] -} - -const GetCompatibleVersion = (versions, minecraftVersion, loader = null) => -{ - if (!versions || !versions.length) - return null - - const compatible = versions.filter(v => - { - const hasVersion = v.game_versions.includes(minecraftVersion) - const hasLoader = loader ? v.loaders.includes(loader) : true - return hasVersion && hasLoader - }) - - if (!compatible.length) - return null - - return compatible.sort((a, b) => new Date(b.date_published) - new Date(a.date_published))[0] -} - -const DownloadFile = async (url, destPath) => -{ - const fs = require("fs-extra") - - try - { - const response = await axios.get(url, { responseType: "arraybuffer" }) - await fs.writeFile(destPath, response.data) - return true - } - catch (err) - { - console.error(`[Download] Failed:`, err.message) - return false - } -} - -module.exports = -{ - MODRINTH_API, - GetModVersions, - GetLatestVersion, - GetCompatibleVersion, - DownloadFile -} - |
