forked from hexparrot/mineos-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
papertemplate.js
57 lines (49 loc) · 1.86 KB
/
papertemplate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var path = require('path');
var fs = require('fs-extra');
var profile = require('./template');
var axios = require('axios');
module.exports = function papertemplate (name){
const lowername = name.toLowerCase();
const titlename = name.charAt(0).toUpperCase() + lowername.substr(1);
return {
name: titlename,
request_args: {
url: `https://papermc.io/api/v2/projects/${lowername}/`,
json: true
},
handler: function (profile_dir, body, callback) {
var p = [];
var weight = 0;
try {
for (var index in body.versions) {
var version = body.versions[index];
p.push(axios({ url: `https://papermc.io/api/v2/projects/${lowername}/versions/${version}/`}).catch((err) => {
console.log(err);
}));
}
Promise.all(p).then(responses => {
p = [];
responses.forEach(response => {
var build = response.data.builds[ response.data.builds.length -1 ];
const splitPath = response.request.path.split('/');
var ver =splitPath[splitPath.length - 2];
var item = new profile();
item['id'] = `${titlename}-${ver}-${build}`;
item['group'] = lowername;
item['webui_desc'] = `Latest ${titlename} build for ${ver}`;
item['weight'] = weight;
item['filename'] = `${lowername}-${ver}-${build}.jar`;
item['url'] = `${response.request.res.responseUrl}builds/${build}/downloads/${lowername}-${ver}-${build}.jar`;
item['downloaded'] = fs.existsSync(path.join(profile_dir, item.id, item.filename));
item['version'] = ver;
item['release_version'] = ver;
item['type'] = 'release'
p.push(item);
weight++;
})
}).then(() => { callback(null, p)})
.catch((err) => {console.error(err)});
} catch (e) { console.log(e) }
} //end handler
}
}