blob: afca78220e9c56f35495ac5bba04c767acdb40d6 (
plain)
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
|
"use strict";
/**
* Fetch the Mojang username API through api.ashcon.app
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.usernameFromUser = exports.uuidFromUser = exports.mojangDataFromUser = void 0;
const node_fetch_1 = __importDefault(require("node-fetch"));
const https_1 = require("https");
// We need to create an agent to prevent memory leaks
const httpsAgent = new https_1.Agent({
keepAlive: true
});
/**
* Get mojang api data from ashcon.app
*/
async function mojangDataFromUser(user) {
const fetchResponse = await node_fetch_1.default('https://api.ashcon.app/mojang/v2/user/' + user, { agent: () => httpsAgent });
return await fetchResponse.json();
}
exports.mojangDataFromUser = mojangDataFromUser;
/**
* Fetch the uuid from a user
* @param user A user can be either a uuid or a username
*/
async function uuidFromUser(user) {
const fetchJSON = await mojangDataFromUser(user);
return fetchJSON.uuid.replace(/-/g, '');
}
exports.uuidFromUser = uuidFromUser;
/**
* Fetch the username from a user
* @param user A user can be either a uuid or a username
*/
async function usernameFromUser(user) {
// get a minecraft uuid from a username, using ashcon.app's mojang api
const fetchJSON = await mojangDataFromUser(user);
return fetchJSON.username;
}
exports.usernameFromUser = usernameFromUser;
|