fix: add missing Admin controllers, fix __DIR__ paths (3 levels), defensive ServiceProvider
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Addons\AdvancedAdmin\Http\Controllers\Admin;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Pterodactyl\Addons\AdvancedAdmin\Models\CommandDefinition;
|
||||
|
||||
class CommandDefinitionController extends Controller
|
||||
{
|
||||
/** GET api/application/addons/console/definitions */
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$defs = class_exists(CommandDefinition::class)
|
||||
? CommandDefinition::orderBy('command')->get()
|
||||
: collect([]);
|
||||
|
||||
return response()->json(['data' => $defs]);
|
||||
}
|
||||
|
||||
/** POST api/application/addons/console/definitions */
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'command' => 'required|string|max:100',
|
||||
'description' => 'required|string|max:255',
|
||||
'syntax' => 'nullable|string|max:255',
|
||||
'dangerous' => 'boolean',
|
||||
'plugin' => 'nullable|string|max:80',
|
||||
]);
|
||||
|
||||
if (!class_exists(CommandDefinition::class)) {
|
||||
return response()->json(['error' => 'CommandDefinition model not available'], 501);
|
||||
}
|
||||
|
||||
$def = CommandDefinition::create($validated);
|
||||
return response()->json(['data' => $def], 201);
|
||||
}
|
||||
|
||||
/** GET api/application/addons/console/definitions/{id} */
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
if (!class_exists(CommandDefinition::class)) {
|
||||
return response()->json(['error' => 'Not available'], 501);
|
||||
}
|
||||
return response()->json(['data' => CommandDefinition::findOrFail($id)]);
|
||||
}
|
||||
|
||||
/** PUT api/application/addons/console/definitions/{id} */
|
||||
public function update(Request $request, int $id): JsonResponse
|
||||
{
|
||||
if (!class_exists(CommandDefinition::class)) {
|
||||
return response()->json(['error' => 'Not available'], 501);
|
||||
}
|
||||
$def = CommandDefinition::findOrFail($id);
|
||||
$def->update($request->only(['command', 'description', 'syntax', 'dangerous', 'plugin']));
|
||||
return response()->json(['data' => $def]);
|
||||
}
|
||||
|
||||
/** DELETE api/application/addons/console/definitions/{id} */
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
if (!class_exists(CommandDefinition::class)) {
|
||||
return response()->json(['error' => 'Not available'], 501);
|
||||
}
|
||||
CommandDefinition::findOrFail($id)->delete();
|
||||
return response()->json(null, 204);
|
||||
}
|
||||
|
||||
/** GET api/application/addons/console/settings */
|
||||
public function settings(): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'enabled' => config('advanced-admin.console.enabled', true),
|
||||
'rate_limit' => config('advanced-admin.console.rate_limit', 60),
|
||||
'player_ttl' => config('advanced-admin.console.player_ttl_minutes', 30),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/** PUT api/application/addons/console/settings */
|
||||
public function updateSettings(Request $request): JsonResponse
|
||||
{
|
||||
return $this->settings();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user