Skip to content

Commit

Permalink
added spongevanilla
Browse files Browse the repository at this point in the history
  • Loading branch information
hexparrot committed May 26, 2016
1 parent 5f06a34 commit e1f7cbc
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
1 change: 1 addition & 0 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ <h4 class="title" translate="AVAILABLE_SERVER_JARS"></h4>
<option value="imagicalmine">ImagicalMine</option>
<option value="php">Pocketmine-php</option>
<option value="bungeecord">BungeeCord</option>
<option value="spongevanilla">SpongeVanilla</option>
<option value="all">Show All</option>
</select>
</td>
Expand Down
93 changes: 92 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,57 @@ function check_profiles(base_dir, callback) {
callback(null, p);
}
request({ url: BUNGEE_VERSIONS_URL, json: false }, handle_reply);
},
spongevanilla: function(callback) {
var xml_parser = require('xml2js');

var SPONGEVANILLA_VERSIONS_URL = 'https://repo.spongepowered.org/maven/org/spongepowered/spongevanilla/maven-metadata.xml';
var path_prefix = path.join(base_dir, mineos.DIRS['profiles']);

function handle_reply(err, response, body) {
var p = [];

if (!err && (response || {}).statusCode === 200)
xml_parser.parseString(body, function(inner_err, result) {
try {
var packs = result['metadata']['versioning'][0]['versions'][0]['version'];

for (var index in packs) {
var item = new profile_template();
var matches = packs[index].match(/([\d\.]+)-([\d\.]+)?-?(\D+)-(\d+)/);

item['version'] = packs[index];
item['group'] = 'spongevanilla';

switch (matches[3]) {
case 'DEV':
item['type'] = 'snapshot';
break;
case 'BETA':
item['type'] = 'release';
break;
default:
item['type'] = 'old_versions';
break;
}

item['id'] = 'SpongeVanilla-{0}{1}{2}'.format(matches[1], matches[3][0].toLowerCase(), matches[4]);
item['webui_desc'] = 'Version {0}, build {1} (mc: {2})'.format(matches[2], matches[4], matches[1]);
item['weight'] = 5;
item['filename'] = 'spongevanilla-{0}.jar'.format(item.version);
item['downloaded'] = fs.existsSync(path.join(base_dir, mineos.DIRS['profiles'], item.id, item.filename));
item['url'] = 'https://repo.spongepowered.org/maven/org/spongepowered/spongevanilla/{0}/spongevanilla-{0}.jar'.format(item.version);
p.push(item);
}
callback(err || inner_err, p);
} catch (e) {
callback(e, p)
}
})
else
callback(null, p);
}
request({ url: SPONGEVANILLA_VERSIONS_URL, json: false, gzip: true }, handle_reply);
}
} //end sources

Expand Down Expand Up @@ -2162,7 +2213,47 @@ function download_profiles(base_dir, args, progress_update_fn, callback) {
.pipe(fs.createWriteStream(dest_filepath))
}
});
}
},
spongevanilla: function(inner_callback) {
var dest_dir = path.join(base_dir, 'profiles', args.id);
var dest_filepath = path.join(dest_dir, args.filename);

var url = args.url;

fs.ensureDir(dest_dir, function(err) {
if (err) {
logging.error('[WEBUI] Error attempting download:', err);
} else {
progress(request(url), {
throttle: 1000,
delay: 100
})
.on('complete', function(response) {
if (response.statusCode == 200) {
logging.log('[WEBUI] Successfully downloaded {0} to {1}'.format(url, dest_filepath));
args['dest_dir'] = dest_dir;
args['success'] = true;
args['progress']['percent'] = 100;
args['help_text'] = 'Successfully downloaded {0} to {1}'.format(url, dest_filepath);
args['suppress_popup'] = false;
inner_callback(args);
} else {
logging.error('[WEBUI] Server was unable to download file:', url);
logging.error('[WEBUI] Remote server returned status {0} with headers:'.format(response.statusCode), response.headers);
args['success'] = false;
args['help_text'] = 'Remote server did not return {0} (status {1})'.format(args.filename, response.statusCode);
args['suppress_popup'] = false;
inner_callback(args);
}
})
.on('progress', function(state) {
args['progress'] = state;
progress_update_fn(args);
})
.pipe(fs.createWriteStream(dest_filepath))
}
});
},
} // end downloads {}

DOWNLOADS[args.group](callback);
Expand Down

0 comments on commit e1f7cbc

Please sign in to comment.