From f089993ea420a7a8aa21f023d2fd312ed2c45c53 Mon Sep 17 00:00:00 2001 From: Daniel Scalzi Date: Thu, 25 Oct 2018 12:45:32 -0400 Subject: [PATCH] Use launchermeta.mojang.com instead of S3 (deprecated). (#12) The deprecated endpoint will be removed by the end of 2018. --- app/assets/js/assetguard.js | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/app/assets/js/assetguard.js b/app/assets/js/assetguard.js index dae336a..a98f47e 100644 --- a/app/assets/js/assetguard.js +++ b/app/assets/js/assetguard.js @@ -1005,12 +1005,11 @@ class AssetGuard extends EventEmitter { */ loadVersionData(version, force = false){ const self = this - return new Promise((resolve, reject) => { - const name = version + '.json' - const url = 'https://s3.amazonaws.com/Minecraft.Download/versions/' + version + '/' + name + return new Promise(async (resolve, reject) => { const versionPath = path.join(self.commonPath, 'versions', version) - const versionFile = path.join(versionPath, name) + const versionFile = path.join(versionPath, version + '.json') if(!fs.existsSync(versionFile) || force){ + const url = await self._getVersionDataUrl(version) //This download will never be tracked as it's essential and trivial. console.log('Preparing download of ' + version + ' assets.') mkpath.sync(versionPath) @@ -1024,6 +1023,34 @@ class AssetGuard extends EventEmitter { }) } + /** + * Parses Mojang's version manifest and retrieves the url of the version + * data index. + * + * @param {string} version The version to lookup. + * @returns {Promise.} Promise which resolves to the url of the version data index. + * If the version could not be found, resolves to null. + */ + _getVersionDataUrl(version){ + return new Promise((resolve, reject) => { + request('https://launchermeta.mojang.com/mc/game/version_manifest.json', (error, resp, body) => { + if(error){ + reject(error) + } else { + const manifest = JSON.parse(body) + + for(let v of manifest.versions){ + if(v.id === version){ + resolve(v.url) + } + } + + resolve(null) + } + }) + }) + } + // Asset (Category=''') Validation Functions // #region