/
app.js
120 lines (104 loc) · 3.11 KB
/
app.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// https://wiki.vg/Mojang_API
const request = require("request-promise-native");
const express = require("express");
const Jimp = require("jimp");
const fs = require("fs");
var app = express();
/*
const getUUID = username=>new Promise((resolve, reject)=>{
request("https://api.mojang.com/users/profiles/minecraft/"+username).then(json=>{
try {
json = JSON.parse(json);
if (json.id==undefined) return reject("Could not parse JSON");
return resolve(json.id);
} catch {
return reject("Could not parse JSON");
}
}).catch(err=>{
return reject("Username not found");
});
});
const getSkin = uuid=>new Promise((resolve, reject)=>{
request("https://sessionserver.mojang.com/session/minecraft/profile/"+uuid).then(json=>{
try {
json = JSON.parse(json);
if (json.properties==undefined) return reject("Skin not found");
if (json.properties[0]==undefined) return reject("Skin not found");
if (json.properties[0].value==undefined) return reject("Skin not found");
return resolve("data:image/png;base64,"+json.properties[0].value);
} catch {
return reject("Could not parse JSON");
}
}).catch(err=>{
return reject("UUID not found");
});
});
*/
const getSkin = username=>new Promise((resolve, reject)=>{
request({
url:"https://minecraftskinstealer.com/api/v1/skin/download/skin/"+username,
encoding:null
}).then(skin=>{
return resolve(skin);
}).catch(err=>{
return reject("Username not found");
});
});
var skinCache = {};
app.get("/skin/:username", async (req,res)=>{
if (!req.params.username) return res.end();
let username = req.params.username;
if (username.toLowerCase().endsWith(".png")) {
username = username.substring(0, username.length-4);
}
if (skinCache[username]!=undefined) {
res.setHeader("Content-Type", "image/png");
res.end(skinCache[username]);
return;
}
getSkin(username).then(skin=>{
Jimp.read(skin).then(image=>{
if (image.bitmap.height==32)
image.contain(64, 64, Jimp.VERTICAL_ALIGN_TOP);
image.resize(2048, 2048, Jimp.RESIZE_NEAREST_NEIGHBOR);
image.getBufferAsync(Jimp.MIME_PNG).then(buffer=>{
skinCache[username] = buffer;
res.setHeader("Content-Type", "image/png");
res.end(buffer);
}).catch(err=>{
return res.end();
});
}).catch(err=>{
return res.end();
});
}).catch(err=>{
return res.end();
});
});
app.get("/avatar.fbx", (req,res)=>{
res.end(fs.readFileSync(__dirname+"/avatar.fbx"));
});
app.get("/:username", (req,res)=>{
if (!req.params.username) return res.end();
let username = req.params.username;
if (username.toLowerCase().endsWith(".fst")) {
username = username.substring(0, username.length-4);
}
let url = "https://maki.cat/mc-hifi/skin/"+username+".png";
let fst = fs.readFileSync(__dirname+"/avatar.fst", "utf8");
let materialMap = {
all: {
materials: {
unlit: true,
albedoMap: url,
opacityMap: url,
}
}
}
fst += "\nmaterialMap = "+JSON.stringify(materialMap);
res.end(fst);
});
var port = 8086;
app.listen(port, ()=>{
console.log("Server up on *:"+port);
});