55use Carbon \CarbonImmutable ;
66use Pterodactyl \Models \Server ;
77use Illuminate \Http \JsonResponse ;
8+ use Pterodactyl \Services \Servers \StartupCommandService ;
89use Pterodactyl \Services \Servers \VariableValidatorService ;
910use Pterodactyl \Repositories \Eloquent \ServerVariableRepository ;
1011use Pterodactyl \Transformers \Api \Client \EggVariableTransformer ;
1112use Pterodactyl \Http \Controllers \Api \Client \ClientApiController ;
1213use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
1314use Symfony \Component \HttpKernel \Exception \BadRequestHttpException ;
15+ use Pterodactyl \Http \Requests \Api \Client \Servers \Startup \GetStartupRequest ;
1416use Pterodactyl \Http \Requests \Api \Client \Servers \Startup \UpdateStartupVariableRequest ;
1517
1618class StartupController extends ClientApiController
@@ -25,18 +27,45 @@ class StartupController extends ClientApiController
2527 */
2628 private $ repository ;
2729
30+ /**
31+ * @var \Pterodactyl\Services\Servers\StartupCommandService
32+ */
33+ private $ startupCommandService ;
34+
2835 /**
2936 * StartupController constructor.
3037 *
3138 * @param \Pterodactyl\Services\Servers\VariableValidatorService $service
39+ * @param \Pterodactyl\Services\Servers\StartupCommandService $startupCommandService
3240 * @param \Pterodactyl\Repositories\Eloquent\ServerVariableRepository $repository
3341 */
34- public function __construct (VariableValidatorService $ service , ServerVariableRepository $ repository )
42+ public function __construct (VariableValidatorService $ service , StartupCommandService $ startupCommandService , ServerVariableRepository $ repository )
3543 {
3644 parent ::__construct ();
3745
3846 $ this ->service = $ service ;
3947 $ this ->repository = $ repository ;
48+ $ this ->startupCommandService = $ startupCommandService ;
49+ }
50+
51+ /**
52+ * Returns the startup information for the server including all of the variables.
53+ *
54+ * @param \Pterodactyl\Http\Requests\Api\Client\Servers\Startup\GetStartupRequest $request
55+ * @param \Pterodactyl\Models\Server $server
56+ * @return array
57+ */
58+ public function index (GetStartupRequest $ request , Server $ server )
59+ {
60+ $ startup = $ this ->startupCommandService ->handle ($ server , false );
61+
62+ return $ this ->fractal ->collection ($ server ->variables )
63+ ->transformWith ($ this ->getTransformer (EggVariableTransformer::class))
64+ ->addMeta ([
65+ 'startup_command ' => $ startup ,
66+ 'raw_startup_command ' => $ server ->startup ,
67+ ])
68+ ->toArray ();
4069 }
4170
4271 /**
@@ -78,8 +107,14 @@ public function update(UpdateStartupVariableRequest $request, Server $server)
78107 $ variable = $ variable ->refresh ();
79108 $ variable ->server_value = $ request ->input ('value ' );
80109
110+ $ startup = $ this ->startupCommandService ->handle ($ server , false );
111+
81112 return $ this ->fractal ->item ($ variable )
82113 ->transformWith ($ this ->getTransformer (EggVariableTransformer::class))
114+ ->addMeta ([
115+ 'startup_command ' => $ startup ,
116+ 'raw_startup_command ' => $ server ->startup ,
117+ ])
83118 ->toArray ();
84119 }
85120}
0 commit comments