@@ -40,6 +40,45 @@ const seed = async () => {
40
40
} ;
41
41
seed ( ) ;
42
42
43
+ // recheck all uuid that is NULL or 'NULL'
44
+ const recheck = async ( ) => {
45
+ let conn ;
46
+ try {
47
+ conn = await pool . getConnection ( ) ;
48
+ const sql = "SELECT * FROM users WHERE uuid IS NULL OR uuid = 'NULL'" ;
49
+ const rows = await conn . query ( sql ) ;
50
+ console . log ( `Rechecking ${ rows . length } users` ) ;
51
+ for ( const row of rows ) {
52
+ const response = await fetch (
53
+ `https://api.mojang.com/users/profiles/minecraft/${ row . username } ` ,
54
+ ) ;
55
+ if ( response . status === 404 ) {
56
+ console . log ( `Failed to get uuid for ${ row . username } ` ) ;
57
+ continue ;
58
+ }
59
+ if ( ! response . ok ) {
60
+ console . log ( `Failed to get uuid for ${ row . username } ` ) ;
61
+ continue ;
62
+ }
63
+ const uuid = ( await response . json ( ) ) . id ;
64
+ if ( ! uuid || uuid == null ) {
65
+ console . log ( `Failed to get uuid for ${ row . username } : ${ uuid } ` ) ;
66
+ continue ;
67
+ }
68
+ const updateSql = "UPDATE users SET uuid = ? WHERE username = ?" ;
69
+ await conn . query ( updateSql , [ uuid , row . username ] ) ;
70
+ console . log ( `Updated UUID for ${ row . username } to ${ uuid } ` ) ;
71
+ }
72
+ } catch ( err ) {
73
+ console . error ( err ) ;
74
+ console . log ( "Retrying in 30 minutes" ) ;
75
+ setTimeout ( recheck , 30 * 60 * 1000 ) ;
76
+ } finally {
77
+ if ( conn ) conn . end ( ) ;
78
+ }
79
+ }
80
+ recheck ( ) ;
81
+
43
82
const app = express ( ) ;
44
83
app . use ( express . static ( "../frontend/dist" ) ) ; // use public
45
84
app . use ( express . json ( ) ) ; // to support JSON-encoded bodies
@@ -94,7 +133,11 @@ app.post("/register", async (req, res) => {
94
133
return ;
95
134
}
96
135
97
- const uuid = await response . json ( ) . id ;
136
+ const json = await response . json ( ) ;
137
+ console . log ( json ) ;
138
+ const uuid = json . id ;
139
+
140
+ console . log ( `UUID for ${ username } is ${ uuid } ` ) ;
98
141
99
142
if ( ! uuid || uuid == null ) {
100
143
console . log ( `Failed to get uuid for ${ username } : ${ uuid } ` ) ;
0 commit comments