@@ -8,7 +8,7 @@ import { commands } from './commands/index.js';
88import { components } from './components/index.js' ;
99import { modals } from './modals/index.js' ;
1010import { JsonResponse } from './response.js' ;
11- import { logger , type Env , type LinkedAccount } from './util.js' ;
11+ import { logger , type Env , type LinkedAccount , type LinkedSibling } from './util.js' ;
1212
1313const router = Router < IRequest , [ Env , ExecutionContext , API ] > ( ) ;
1414
@@ -90,7 +90,7 @@ router.post('/api/interactions/handle', async (req, env, ctx, api) => {
9090 } ) ;
9191 }
9292
93- return component . handle ( req , ctx , message ) ;
93+ return component . handle ( req , ctx , env , message ) ;
9494 }
9595
9696 case InteractionType . ApplicationCommandAutocomplete : {
@@ -133,21 +133,56 @@ router.get('/api/whitelist', async (req, env) => {
133133 return new Response ( 'Unauthorized' , { status : 401 } ) ;
134134 }
135135
136- const { results : connections } = await env . DB . prepare ( 'SELECT * FROM linked_accounts' ) . all < LinkedAccount > ( ) ;
136+ const { results : connectionsRaw } = await env . DB . prepare ( 'SELECT * FROM linked_accounts' ) . all < LinkedAccount > ( ) ;
137+ const { results : siblingConnections } = await env . DB . prepare ( 'SELECT * FROM linked_siblings' ) . all < LinkedSibling > ( ) ;
138+
139+ const connections = connectionsRaw . map ( ( connection ) => {
140+ const siblings = siblingConnections
141+ . filter ( ( sibling ) => sibling . discord_id === connection . discord_id )
142+ . map ( ( sibling ) => sibling . sibling_username ) ;
143+
144+ return {
145+ ...connection ,
146+ siblings,
147+ } ;
148+ } ) ;
149+
137150 return new JsonResponse (
138- connections . map ( ( conn ) => ( { discord_id : conn . discord_id , minecraft_username : conn . minecraft_username } ) ) ,
151+ connections . map ( ( conn ) => ( {
152+ discord_id : conn . discord_id ,
153+ java_username : conn . java_username ,
154+ bedrock_username : conn . bedrock_username ,
155+ sibling_usernames : conn . siblings ,
156+ } ) ) ,
139157 { status : 200 } ,
140158 ) ;
141159} ) ;
142160
143- router . put ( '/api/whitelist/verify/:discord_id' , async ( req , env ) => {
161+ router . put ( '/api/whitelist/java/verify/:discord_id' , async ( req , env ) => {
162+ const headers = req . headers as Headers ;
163+ if ( headers . get ( 'authorization' ) !== env . AUTH_PASS ) {
164+ return new Response ( 'Unauthorized' , { status : 401 } ) ;
165+ }
166+
167+ const { discord_id } = req . params ;
168+ const updated = await env . DB . prepare (
169+ 'UPDATE linked_accounts SET java_confirmed = true WHERE discord_id = ? RETURNING *' ,
170+ )
171+ . bind ( discord_id )
172+ . first < LinkedAccount > ( ) ;
173+ return new JsonResponse ( updated ! , { status : 200 } ) ;
174+ } ) ;
175+
176+ router . put ( '/api/whitelist/bedrock/verify/:discord_id' , async ( req , env ) => {
144177 const headers = req . headers as Headers ;
145178 if ( headers . get ( 'authorization' ) !== env . AUTH_PASS ) {
146179 return new Response ( 'Unauthorized' , { status : 401 } ) ;
147180 }
148181
149182 const { discord_id } = req . params ;
150- const updated = await env . DB . prepare ( 'UPDATE linked_accounts SET confirmed = true WHERE discord_id = ? RETURNING *' )
183+ const updated = await env . DB . prepare (
184+ 'UPDATE linked_accounts SET bedrock_confirmed = true WHERE discord_id = ? RETURNING *' ,
185+ )
151186 . bind ( discord_id )
152187 . first < LinkedAccount > ( ) ;
153188 return new JsonResponse ( updated ! , { status : 200 } ) ;
0 commit comments