Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Mojang profile #539

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 53 additions & 72 deletions profiles.d/mojang.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,69 @@
var async = require('async');
var path = require('path');
var fs = require('fs-extra');
var profile = require('./template');
const async = require('async');
const axios = require('axios');
const path = require('path');
const fs = require('fs-extra');
const profile = require('./template');

exports.profile = {
name: "Mojang Official Minecraft Jars",
request_args: {
url: 'https://launchermeta.mojang.com/mc/game/version_manifest.json',
url: 'https://piston-meta.mojang.com/mc/game/version_manifest.json',
json: true
},
handler: function (profile_dir, body, callback) {
var request = require('request');
var p = [];
const profiles = [];

var q = async.queue(function (obj, cb) {
async.waterfall([
async.apply(request, obj.url),
function (response, body, inner_cb) {
inner_cb(response.statusCode != 200, body)
},
function (body, inner_cb) {
try {
var parsed = JSON.parse(body);
} catch (err) {
callback(err);
inner_cb(err);
return;
}
for (var idx in p)
if (p[idx]['id'] == obj['id'])
try {
p[idx]['url'] = parsed['downloads']['server']['url'];
} catch (e) { }
inner_cb();
}
])
cb();
}, 2);
try {
const queue = async.queue(function (task, cb) {
// Request to metadata json of version
axios({ url: task.url, responseType: 'json' })
.then(response => {
if (response.status !== 200) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}

q.pause();
const data = response.data;

try { // BEGIN PARSING LOGIC
for (var index in body.versions) {
var item = new profile();
var ref_obj = body.versions[index];
let item = new profile();
item.id = data.id;
item.time = data.time;
item.releaseTime = data.releaseTime;
item.group = 'mojang';
item.webui_desc = 'Official Mojang Jar';
item.weight = 0;
item.filename = `minecraft_server.${item.id}.jar`;
item.downloaded = fs.existsSync(path.join(profile_dir, item.id, item.filename));
item.version = item.id;
item.release_version = item.id;
item.type = data.type;

item['id'] = ref_obj['id'];
item['time'] = ref_obj['time'];
item['releaseTime'] = ref_obj['releaseTime'];
item['group'] = 'mojang';
item['webui_desc'] = 'Official Mojang Jar';
item['weight'] = 0;
item['filename'] = 'minecraft_server.{0}.jar'.format(ref_obj['id']);
item['downloaded'] = fs.existsSync(path.join(profile_dir, item.id, item.filename));
item['version'] = ref_obj['id'];
item['release_version'] = ref_obj['id'];
item['url'] = 'https://s3.amazonaws.com/Minecraft.Download/versions/{0}/minecraft_server.{0}.jar'.format(item.version);
if (data.downloads.server) {
item.url = data.downloads.server.url;
profiles.push(item);
} else {
console.warn("No server jar:", data);
}

cb();
})
.catch((err) => {
console.error(err);
callback(err);
});
}, 2);

switch (ref_obj['type']) {
case 'release':
item['type'] = ref_obj['type'];
q.push({ id: item['id'], url: ref_obj.url });
p.push(item);
break;
case 'snapshot':
item['type'] = ref_obj['type'];
q.push({ id: item['id'], url: ref_obj.url });
p.push(item);
break;
default:
item['type'] = 'old_version'; //old_alpha, old_beta
//q.push({ id: item['id'], url: ref_obj.url });
break;
queue.drain = function () {
callback(null, profiles);
};

for (const version of body.versions) {
const task = { id: version.id, type: version.type, url: version.url };

// Only releases or snapshots; other types (e.g. old_alpha, old_beta) have no server jar
if (task.type === 'release' || task.type === 'snapshot') {
queue.push(task);
}
//p.push(item);
}
} catch (e) { }

q.resume();
q.drain = function () {
callback(null, p);
}
}, //end handler
postdownload: function (profile_dir, dest_filepath, callback) {
callback();
} catch (e) { console.error(e) }
}
}