This repository was archived by the owner on Sep 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
48 lines (48 loc) · 1.97 KB
/
main.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
var http = require('http');
var https = require('https');
http.createServer(function(req, res) {
var path = require('path');
var uuid = req.url.toString().substr("/MinecraftSkins".length + 1).substring(0, req.url.toString().substr("/MinecraftSkins".length + 1).length -4);
//console.log(uuid);
var options = {host: 'api.mojang.com',port: 443,path: '/users/profiles/minecraft/' + uuid};
//console.log('api.mojang.com/users/profiles/minecraft/' + uuid);
var request = https.request(options, function(resy) {
var data = '';
resy.on('data', function(chunk) {
data += chunk;
});
resy.on('end', function() {
try {
//console.log(data);
var json = JSON.parse(data);
getImageFromUUID(json.id, res);
} catch (err) {
console.log(uuid +' is not a valid name');
console.log(err + ' <> ' + data);
res.end();
}
});
});
request.on('error', function(e) {
console.log(e.message);
});
request.end();
}).listen(8080);
function getImageFromUUID(uuid, res) {
//console.log('started uuid match with ' + uuid);
var options = {host: 'crafatar.com',port: 443,path: '/skins/' +uuid + '.png'};
var request1 = https.request(options,function(resyy) {
var data = '';
resyy.on('data', function(chunk) {
res.write(chunk);
});
resyy.on('end', function() {
res.write(data);
res.end();
});
});
request1.on('error', function(e) {
console.log(e.message);
});
request1.end();
}