misc_pterodactyl-panel/app/Http/Controllers/Api/Client/Servers/ActivityLogController.php
2022-06-12 15:16:48 -04:00

36 lines
1.2 KiB
PHP

<?php
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\Permission;
use Spatie\QueryBuilder\QueryBuilder;
use Spatie\QueryBuilder\AllowedFilter;
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
use Pterodactyl\Transformers\Api\Client\ActivityLogTransformer;
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
class ActivityLogController extends ClientApiController
{
/**
* Returns the activity logs for a server.
*/
public function __invoke(ClientApiRequest $request, Server $server): array
{
$this->authorize(Permission::ACTION_ACTIVITY_READ, $server);
$activity = QueryBuilder::for($server->activity())
->with('actor')
->allowedSorts(['timestamp'])
->allowedFilters([
AllowedFilter::exact('ip'),
AllowedFilter::partial('event'),
])
->paginate(min($request->query('per_page', 25), 100))
->appends($request->query());
return $this->fractal->collection($activity)
->transformWith($this->getTransformer(ActivityLogTransformer::class))
->toArray();
}
}