Skip to content
Permalink
Browse files

Minecraft skin hifi

  • Loading branch information...
makitsune committed Aug 12, 2019
1 parent 010d243 commit 4259cc8a27c08212215a80dfda100d498d83f602
Showing with 108 additions and 0 deletions.
  1. +1 −0 README.md
  2. +89 −0 express-routes/mc-skin-hifi/app.js
  3. +18 −0 express-routes/mc-skin-hifi/package.json
@@ -91,6 +91,7 @@
## express routes

- [3D Text .obj](https://github.com/makitsune/hifi-things/tree/master/express-routes/3d-text)
- [Minecraft Skin Hifi](https://github.com/makitsune/hifi-things/tree/master/express-routes/mc-skin-hifi)
- [Video Sync](https://github.com/makitsune/hifi-things/tree/master/express-routes/video-sync)

<br><br>
@@ -0,0 +1,89 @@
// https://wiki.vg/Mojang_API
const request = require("request-promise-native");
const express = require("express");
const Jimp = require("jimp");

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("/:username", (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("")
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(4096, 4096, Jimp.RESIZE_NEAREST_NEIGHBOR);
image.getBufferAsync(Jimp.MIME_PNG).then(buffer=>{
skinCache[username] = buffer;
res.end(buffer);
}).catch(err=>{
return res.end();
});
}).catch(err=>{
return res.end();
});
}).catch(err=>{
return res.end();
})
});

app.listen(8080, ()=>{
console.log("Server up on *:8080");
});
@@ -0,0 +1,18 @@
{
"name": "mc-hifi",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"jimp": "^0.6.4",
"request": "^2.88.0",
"request-promise-native": "^1.0.7"
}
}

0 comments on commit 4259cc8

Please sign in to comment.
You can’t perform that action at this time.