@@ -9,7 +9,7 @@ import type { Response as UndiciResponse } from 'undici/types/fetch'
9
9
10
10
// We need to create an agent to prevent memory leaks
11
11
const httpsAgent = new Agent ( {
12
- keepAlive : true
12
+ keepAlive : true ,
13
13
} )
14
14
15
15
interface MojangApiResponse {
@@ -21,13 +21,15 @@ interface MojangApiResponse {
21
21
/**
22
22
* Get mojang api data from the session server
23
23
*/
24
- export let profileFromUuid = async function profileFromUuid ( uuid : string ) : Promise < MojangApiResponse > {
24
+ export let profileFromUuid = async function profileFromUuid (
25
+ uuid : string
26
+ ) : Promise < MojangApiResponse > {
25
27
let fetchResponse : UndiciResponse
26
28
27
29
try {
28
30
fetchResponse = await fetch (
29
31
// using mojang directly is faster than ashcon, also there seem to be no ratelimits here?
30
- `https://sessionserver.mojang.com/session/minecraft/profile/ ${ undashUuid ( uuid ) } ` ,
32
+ `https://mowojang.matdoes.dev/ ${ undashUuid ( uuid ) } `
31
33
)
32
34
} catch {
33
35
// if there's an error, wait a second and try again
@@ -50,20 +52,19 @@ export let profileFromUuid = async function profileFromUuid(uuid: string): Promi
50
52
}
51
53
return {
52
54
uuid : data . id ,
53
- username : data . name
55
+ username : data . name ,
54
56
}
55
57
}
56
58
57
-
58
- export let profileFromUsername = async function profileFromUsername ( username : string ) : Promise < MojangApiResponse > {
59
+ export let profileFromUsername = async function profileFromUsername (
60
+ username : string
61
+ ) : Promise < MojangApiResponse > {
59
62
// since we don't care about anything other than the uuid, we can use /uuid/ instead of /user/
60
63
61
64
let fetchResponse : UndiciResponse
62
65
63
66
try {
64
- fetchResponse = await fetch (
65
- `https://api.mojang.com/users/profiles/minecraft/${ username } ` ,
66
- )
67
+ fetchResponse = await fetch ( `https://mowojang.matdoes.dev/${ username } ` )
67
68
} catch {
68
69
// if there's an error, wait a second and try again
69
70
await sleep ( 1000 )
@@ -74,56 +75,29 @@ export let profileFromUsername = async function profileFromUsername(username: st
74
75
const rawData = await fetchResponse . text ( )
75
76
try {
76
77
data = JSON . parse ( rawData )
77
- } catch { }
78
-
79
-
80
- if ( ! data ?. id ) {
81
- // return { uuid: null, username: null }
82
- return await profileFromUsernameAlternative ( username )
83
- }
78
+ } catch { }
84
79
85
80
return {
86
81
uuid : data . id ,
87
- username : data . name
88
- }
89
- }
90
-
91
- export async function profileFromUsernameAlternative ( username : string ) : Promise < MojangApiResponse > {
92
- let fetchResponse : UndiciResponse
93
-
94
- try {
95
- fetchResponse = await fetch (
96
- `https://api.ashcon.app/mojang/v2/user/${ username } ` ,
97
- )
98
- } catch {
99
- // if there's an error, wait a second and try again
100
- await sleep ( 1000 )
101
- return await profileFromUsernameAlternative ( username )
102
- }
103
-
104
- let data
105
- try {
106
- data = await fetchResponse . json ( )
107
- } catch {
108
- return { uuid : null , username : null }
109
- }
110
- if ( ! data . uuid )
111
- return { uuid : null , username : null }
112
- return {
113
- uuid : undashUuid ( data . uuid ) ,
114
- username : data . username
82
+ username : data . name ,
115
83
}
116
84
}
117
85
118
- export let profileFromUser = async function profileFromUser ( user : string ) : Promise < MojangApiResponse > {
86
+ export let profileFromUser = async function profileFromUser (
87
+ user : string
88
+ ) : Promise < MojangApiResponse > {
119
89
if ( isUuid ( user ) ) {
120
90
return await profileFromUuid ( user )
121
- } else
122
- return await profileFromUsername ( user )
91
+ } else return await profileFromUsername ( user )
123
92
}
124
93
125
-
126
94
// this is necessary for mocking in the tests because es6
127
- export function mockProfileFromUuid ( $value ) { profileFromUuid = $value }
128
- export function mockProfileFromUsername ( $value ) { profileFromUsername = $value }
129
- export function mockProfileFromUser ( $value ) { profileFromUser = $value }
95
+ export function mockProfileFromUuid ( $value ) {
96
+ profileFromUuid = $value
97
+ }
98
+ export function mockProfileFromUsername ( $value ) {
99
+ profileFromUsername = $value
100
+ }
101
+ export function mockProfileFromUser ( $value ) {
102
+ profileFromUser = $value
103
+ }
0 commit comments