From 4a5b47e054c8e9e6de3c7de762b89633061035d7 Mon Sep 17 00:00:00 2001 From: Artemy Date: Sun, 18 Jun 2023 18:52:39 +0300 Subject: [PATCH] feat: get versions --- components/utils.js | 36 ++++++++++++++++++++++++++++++++++ index.js | 7 ++++--- package-lock.json | 48 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 ++- 4 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 components/utils.js diff --git a/components/utils.js b/components/utils.js new file mode 100644 index 0000000..aa5f3f0 --- /dev/null +++ b/components/utils.js @@ -0,0 +1,36 @@ +const axios = require("axios"); + +async function getVersions() { + return ( + await axios.get( + "https://launchermeta.mojang.com/mc/game/version_manifest_v2.json" + ) + ).data.versions; +} + +async function getLatestVersion() { + return getVersions()[0]; +} + +async function getLatestRelease() { + return ( + await axios.get( + "https://launchermeta.mojang.com/mc/game/version_manifest_v2.json" + ) + ).data.latest.release; +} + +async function getLatestSnapshot() { + return ( + await axios.get( + "https://launchermeta.mojang.com/mc/game/version_manifest_v2.json" + ) + ).data.latest.snapshot; +} + +module.exports = { + getVersions, + getLatestVersion, + getLatestRelease, + getLatestSnapshot, +}; diff --git a/index.js b/index.js index 042698f..ac9e7d9 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ module.exports = { - Client: require('./components/launcher'), - Authenticator: require('./components/authenticator') -} + Client: require("./components/launcher"), + Authenticator: require("./components/authenticator"), + utils: require("./components/utils"), +}; diff --git a/package-lock.json b/package-lock.json index b973431..d2880f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "adm-zip": "^0.4.13", + "axios": "^1.4.0", "checksum": "^0.1.1", "request": "^2.88.0", "uuid": "^8.3.2" @@ -295,6 +296,29 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.12.0.tgz", "integrity": "sha512-NmWvPnx0F1SfrQbYwOi7OeaNGokp9XhzNioJ/CSBs8Qa4vxug81mhJEAVZwxXuBmYB5KDRfMq/F3RR0BIU7sWg==" }, + "node_modules/axios": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", + "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -1138,6 +1162,25 @@ "integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -2229,6 +2272,11 @@ "node": ">=0.4.0" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/psl": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", diff --git a/package.json b/package.json index 019b8fc..41336d4 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,12 @@ { "name": "pimi-launcher-core", - "version": "1.0.0", + "version": "1.1.0", "description": "Core for pimi-launcher (Minecraft)", "main": "index.js", "types": "./index.d.ts", "dependencies": { "adm-zip": "^0.4.13", + "axios": "^1.4.0", "checksum": "^0.1.1", "request": "^2.88.0", "uuid": "^8.3.2"