pixelheads 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +45 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +91 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 jojomatik
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# pixelheads
|
|
2
|
+
A library that makes it easy to retrieve skins and faces of minecraft players based on their uuid.
|
|
3
|
+
|
|
4
|
+
## Usage
|
|
5
|
+
1. Run `npm install pixelheads`
|
|
6
|
+
2. Use one of the functions to retrieve the skin or the face as a base64-encoded string.
|
|
7
|
+
```ts
|
|
8
|
+
import pixelheads from "pixelheads";
|
|
9
|
+
|
|
10
|
+
// Returns the entire skin of the player as a base64-encoded string.
|
|
11
|
+
const playerSkin = pixelheads.getSkinAsBase64("uuid");
|
|
12
|
+
|
|
13
|
+
// Returns the face of the player as a base64-encoded string.
|
|
14
|
+
const playerFace = pixelheads.getFaceAsBase64("uuid");
|
|
15
|
+
```
|
|
16
|
+
3. Use one of the return values, e.g. in an `img`-tag:
|
|
17
|
+
```
|
|
18
|
+
<img src="'data:image/png;base64,' + playerFace" alt="face of player"></img>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Building
|
|
22
|
+
Prerequisites:
|
|
23
|
+
- Git
|
|
24
|
+
- Node.js and npm
|
|
25
|
+
- TypeScript installed globally (`npm install -g typescript`)
|
|
26
|
+
|
|
27
|
+
Run the following commands:
|
|
28
|
+
```sh
|
|
29
|
+
git clone https://github.com/jojomatik/pixelheads
|
|
30
|
+
cd pixelheads
|
|
31
|
+
npm install
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
To build, run the following commands:
|
|
35
|
+
```sh
|
|
36
|
+
tsc
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
To pack the project as a tarball, run the following commands:
|
|
40
|
+
```sh
|
|
41
|
+
npm pack
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Licensing
|
|
45
|
+
This project is licensed under the MIT License (MIT). See also [`LICENSE`](LICENSE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Uses the Mojang-API to retrieve a players skin based on the players uuid and returns the skin as a base64 encoded string.
|
|
3
|
+
* @param uuid the uuid of the player
|
|
4
|
+
* @return the skin of the player encoded as a base64-string.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getSkinAsBase64(uuid: string): Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Uses the Mojang-API to retrieve a players skin based on the players uuid and returns the extracted face as a base64 encoded string.
|
|
9
|
+
* @param uuid the uuid of the player
|
|
10
|
+
* @return the face of the player encoded as a base64-string.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getFaceAsBase64(uuid: string): Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAWnE;AAED,wBAAsB,2BAA2B,CAC/C,IAAI,EAAE;IACJ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD,EACD,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,CAAC,CAsBjB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getFaceAsBase64 = exports.getSkinAsBase64 = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const sharp_1 = __importDefault(require("sharp"));
|
|
18
|
+
/**
|
|
19
|
+
* Uses the Mojang-API to retrieve a players skin based on the players uuid and returns the skin as a base64 encoded string.
|
|
20
|
+
* @param uuid the uuid of the player
|
|
21
|
+
* @return the skin of the player encoded as a base64-string.
|
|
22
|
+
*/
|
|
23
|
+
function getSkinAsBase64(uuid) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const response = yield axios_1.default.get("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid);
|
|
26
|
+
// Fetch profile.
|
|
27
|
+
const data = response.data;
|
|
28
|
+
// Define error prefix.
|
|
29
|
+
const errorMessage = "Couldn't retrieve skin for uuid " + uuid + ". Reason: ";
|
|
30
|
+
if (data.error) {
|
|
31
|
+
throw new Error(errorMessage + data.error + ": " + JSON.stringify(data));
|
|
32
|
+
}
|
|
33
|
+
if (!data.properties) {
|
|
34
|
+
throw new Error(errorMessage + "No properties in response: " + JSON.stringify(data));
|
|
35
|
+
}
|
|
36
|
+
// Loop through properties and find 'textures' property.
|
|
37
|
+
for (const property of data.properties) {
|
|
38
|
+
if (property.name === "textures") {
|
|
39
|
+
// Find object containing the skin URL.
|
|
40
|
+
const response = JSON.parse(Buffer.from(property.value, "base64").toString());
|
|
41
|
+
let skinURL;
|
|
42
|
+
// Check if skin URL exists and retrieve it.
|
|
43
|
+
if (response.textures &&
|
|
44
|
+
response.textures.SKIN &&
|
|
45
|
+
(skinURL = response.textures.SKIN.url)) {
|
|
46
|
+
// Fetch skin URL and returns as base64.
|
|
47
|
+
const b64 = yield axios_1.default
|
|
48
|
+
.get(skinURL, { responseType: "arraybuffer" })
|
|
49
|
+
.then((response) => response.data)
|
|
50
|
+
.then((buffer) => {
|
|
51
|
+
return Buffer.from(buffer).toString("base64");
|
|
52
|
+
})
|
|
53
|
+
.catch((error) => console.error(errorMessage + "Could not load buffer for URL " + skinURL, error));
|
|
54
|
+
if (b64)
|
|
55
|
+
return b64;
|
|
56
|
+
else
|
|
57
|
+
throw new Error(errorMessage + "No skin returned for URL " + skinURL);
|
|
58
|
+
}
|
|
59
|
+
else
|
|
60
|
+
throw new Error(errorMessage +
|
|
61
|
+
"No url to skin in response: " +
|
|
62
|
+
JSON.stringify(response));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
throw new Error(errorMessage + "No textures object in response: " + JSON.stringify(data));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
exports.getSkinAsBase64 = getSkinAsBase64;
|
|
69
|
+
/**
|
|
70
|
+
* Uses the Mojang-API to retrieve a players skin based on the players uuid and returns the extracted face as a base64 encoded string.
|
|
71
|
+
* @param uuid the uuid of the player
|
|
72
|
+
* @return the face of the player encoded as a base64-string.
|
|
73
|
+
*/
|
|
74
|
+
function getFaceAsBase64(uuid) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const skin = yield getSkinAsBase64(uuid);
|
|
77
|
+
const buffer = Buffer.from(skin, "base64");
|
|
78
|
+
const sharpSkin = (0, sharp_1.default)(buffer);
|
|
79
|
+
const sharpHead = sharpSkin.extract({ left: 8, top: 8, width: 8, height: 8 });
|
|
80
|
+
return sharpHead
|
|
81
|
+
.toBuffer()
|
|
82
|
+
.then((data) => {
|
|
83
|
+
return data.toString("base64");
|
|
84
|
+
})
|
|
85
|
+
.catch((error) => {
|
|
86
|
+
throw new Error("Couldn't extract head of skin for uuid " + uuid + ". Reason: " + error);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
exports.getFaceAsBase64 = getFaceAsBase64;
|
|
91
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index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AAE;aACV,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YACb,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACjC,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,MAAM,IAAI,KAAK,CACb,yCAAyC,GAAG,IAAI,GAAG,YAAY,GAAG,KAAK,CACxE,CAAC;QACJ,CAAC,CAAC,CAAC;IACP,CAAC;CAAA;AAfD,0CAeC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pixelheads",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A library that makes it easy to retrieve skins and faces of minecraft players based on their uuid.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"minecraft",
|
|
7
|
+
"skin",
|
|
8
|
+
"mojang",
|
|
9
|
+
"API",
|
|
10
|
+
"face"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"prepublish": "tsc",
|
|
14
|
+
"semantic-release": "semantic-release"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist/*",
|
|
18
|
+
"package.json",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"main": "dist/index.js",
|
|
22
|
+
"types": "dist/index.d.ts",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"axios": "^0.25.0",
|
|
25
|
+
"sharp": "^0.29.3"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/sharp": "^0.29.5",
|
|
29
|
+
"@types/uuid": "^8.3.3",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^5.7.0",
|
|
31
|
+
"@typescript-eslint/parser": "^5.7.0",
|
|
32
|
+
"eslint": "^8.5.0",
|
|
33
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
34
|
+
"prettier": "^2.5.1",
|
|
35
|
+
"typescript": "^4.5.4"
|
|
36
|
+
},
|
|
37
|
+
"author": {
|
|
38
|
+
"name": "jojomatik",
|
|
39
|
+
"email": "dev@jojomatik.de"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/jojomatik/pixelheads/issues",
|
|
43
|
+
"email": "dev@jojomatik.de"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/jojomatik/pixelheads",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "https://github.com/jojomatik/pixelheads.git"
|
|
50
|
+
}
|
|
51
|
+
}
|