2022-07-09 21:45:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Http\Requests\Api\Remote;
|
|
|
|
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
|
|
|
|
class ActivityEventRequest extends FormRequest
|
|
|
|
{
|
|
|
|
public function authorize(): bool
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rules(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'data' => ['required', 'array'],
|
|
|
|
'data.*' => ['array'],
|
2022-11-06 22:42:48 +00:00
|
|
|
'data.*.user' => ['sometimes', 'nullable', 'uuid'],
|
2022-07-09 21:45:38 +00:00
|
|
|
'data.*.server' => ['required', 'uuid'],
|
|
|
|
'data.*.event' => ['required', 'string'],
|
|
|
|
'data.*.metadata' => ['present', 'nullable', 'array'],
|
2022-11-06 22:42:48 +00:00
|
|
|
'data.*.ip' => ['sometimes', 'nullable', 'ip'],
|
2022-07-09 21:45:38 +00:00
|
|
|
'data.*.timestamp' => ['required', 'string'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-14 16:59:20 +00:00
|
|
|
* Returns all the unique server UUIDs that were received in this request.
|
2022-07-09 21:45:38 +00:00
|
|
|
*/
|
|
|
|
public function servers(): array
|
|
|
|
{
|
|
|
|
return Collection::make($this->input('data'))->pluck('server')->unique()->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-10-14 16:59:20 +00:00
|
|
|
* Returns all the unique user UUIDs that were submitted in this request.
|
2022-07-09 21:45:38 +00:00
|
|
|
*/
|
|
|
|
public function users(): array
|
|
|
|
{
|
|
|
|
return Collection::make($this->input('data'))
|
|
|
|
->filter(function ($value) {
|
|
|
|
return !empty($value['user']);
|
|
|
|
})
|
|
|
|
->pluck('user')
|
|
|
|
->unique()
|
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
}
|