@@ -186,6 +186,27 @@ router.get('/details/:id', authenticateToken, async (req, res) => {
186186 const server = await getServerById ( serverId ) ;
187187 const meta = await query ( 'SELECT * FROM server_meta WHERE ptero_server_id = ?' , [ serverId ] ) ;
188188 server . serverMeta = meta . length > 0 ? meta [ 0 ] : null ;
189+
190+ const users = await query ( 'SELECT ptero_client_api_key FROM users WHERE id = ?' , [ req . user . userId ] ) ;
191+ const clientApiKey = users [ 0 ] ?. ptero_client_api_key ;
192+ if ( clientApiKey ) {
193+ try {
194+ const pteroRes = await fetch ( `${ PTERO_URL } /api/client/servers/${ server . identifier } /resources` , {
195+ headers : {
196+ 'Authorization' : `Bearer ${ clientApiKey } ` ,
197+ 'Accept' : 'application/json' ,
198+ } ,
199+ signal : AbortSignal . timeout ( 8000 ) ,
200+ } ) ;
201+ if ( pteroRes . ok ) {
202+ const data = await pteroRes . json ( ) ;
203+ server . currentState = data . attributes . current_state ;
204+ }
205+ } catch {
206+ server . currentState = null ;
207+ }
208+ }
209+
189210 res . json ( { server } ) ;
190211 } catch ( err ) {
191212 console . error ( 'Get server error:' , err . message ) ;
@@ -390,6 +411,40 @@ router.get('/resources/:identifier', authenticateToken, async (req, res) => {
390411 }
391412} ) ;
392413
414+ router . post ( '/power/:identifier' , authenticateToken , async ( req , res ) => {
415+ try {
416+ const { identifier } = req . params ;
417+ const { signal } = req . body ;
418+ const userId = req . user . userId ;
419+
420+ const users = await query ( 'SELECT ptero_client_api_key FROM users WHERE id = ?' , [ userId ] ) ;
421+ if ( ! users [ 0 ] ?. ptero_client_api_key ) {
422+ return res . status ( 400 ) . json ( { error : 'No Pyrodactyl API key configured' } ) ;
423+ }
424+
425+ const apiKey = users [ 0 ] . ptero_client_api_key ;
426+ const pteroRes = await fetch ( `${ PTERO_URL } /api/client/servers/${ identifier } /power` , {
427+ method : 'POST' ,
428+ headers : {
429+ 'Authorization' : `Bearer ${ apiKey } ` ,
430+ 'Accept' : 'application/json' ,
431+ 'Content-Type' : 'application/json' ,
432+ } ,
433+ body : JSON . stringify ( { signal } ) ,
434+ signal : AbortSignal . timeout ( 10000 ) ,
435+ } ) ;
436+
437+ if ( ! pteroRes . ok ) {
438+ return res . status ( 502 ) . json ( { error : 'Failed to send power command' } ) ;
439+ }
440+
441+ res . json ( { success : true } ) ;
442+ } catch ( err ) {
443+ console . error ( 'Power command error:' , err . message ) ;
444+ res . status ( 500 ) . json ( { error : 'Failed to send power command' } ) ;
445+ }
446+ } ) ;
447+
393448router . put ( '/client-api-key' , authenticateToken , async ( req , res ) => {
394449 try {
395450 const { apiKey } = req . body ;
0 commit comments