@@ -3,7 +3,7 @@ import argon2 from 'argon2';
33import jwt from 'jsonwebtoken' ;
44import { authenticateToken } from '../middleware/auth.js' ;
55import { query } from '../config/db.js' ;
6- import { getAllServers , getServerById , getEgg , getPteroNests , getPteroNestEggs , suspendPteroServer , unsuspendPteroServer , deletePteroServer , deletePteroUser } from '../services/pyrodactyl.js' ;
6+ import { getAllServers , getServerById , getEgg , getPteroNests , getPteroNestEggs , suspendPteroServer , unsuspendPteroServer , deletePteroServer , deletePteroUser , updatePteroServerBuild , getPergoServerIdsByEgg } from '../services/pyrodactyl.js' ;
77import { verifyCap } from '../config/cap.js' ;
88import { logActivity } from '../services/activity.js' ;
99
@@ -603,4 +603,47 @@ router.put('/settings/eggs/:nestId/:eggId', authenticateToken, requireAdmin, asy
603603 }
604604} ) ;
605605
606+ router . post ( '/settings/eggs/:nestId/:eggId/apply-all' , authenticateToken , requireAdmin , async ( req , res ) => {
607+ try {
608+ const { nestId, eggId } = req . params ;
609+ const { cpu_limit, memory_limit, disk_limit } = req . body ;
610+
611+ // Save to egg_resources first
612+ const [ existing ] = await query ( 'SELECT id FROM egg_resources WHERE ptero_nest_id = ? AND ptero_egg_id = ?' , [ nestId , eggId ] ) ;
613+ if ( existing ) {
614+ await query ( 'UPDATE egg_resources SET cpu_limit = ?, memory_limit = ?, disk_limit = ? WHERE id = ?' ,
615+ [ cpu_limit ?? null , memory_limit ?? null , disk_limit ?? null , existing . id ] ) ;
616+ } else {
617+ await query ( 'INSERT INTO egg_resources (ptero_nest_id, ptero_egg_id, cpu_limit, memory_limit, disk_limit) VALUES (?, ?, ?, ?, ?)' ,
618+ [ nestId , eggId , cpu_limit ?? null , memory_limit ?? null , disk_limit ?? null ] ) ;
619+ }
620+
621+ // Find all panel servers using this egg
622+ const pteroIds = await getPergoServerIdsByEgg ( parseInt ( nestId , 10 ) , parseInt ( eggId , 10 ) ) ;
623+
624+ if ( pteroIds . length === 0 ) {
625+ return res . json ( { success : true , updated : 0 , total : 0 } ) ;
626+ }
627+
628+ const limits = { } ;
629+ if ( cpu_limit != null ) limits . cpu = cpu_limit ;
630+ if ( memory_limit != null ) limits . memory = memory_limit ;
631+ if ( disk_limit != null ) limits . disk = disk_limit ;
632+
633+ let updated = 0 ;
634+ for ( const id of pteroIds ) {
635+ try {
636+ await updatePteroServerBuild ( id , limits ) ;
637+ updated ++ ;
638+ } catch ( err ) {
639+ console . error ( `Failed to update server #${ id } build:` , err . message ) ;
640+ }
641+ }
642+
643+ res . json ( { success : true , updated, total : pteroIds . length } ) ;
644+ } catch ( err ) {
645+ res . status ( 500 ) . json ( { error : 'Failed to apply resources to all servers: ' + err . message } ) ;
646+ }
647+ } ) ;
648+
606649export default router ;
0 commit comments