mirror of
https://github.com/pelican-dev/panel.git
synced 2025-08-03 20:02:23 +02:00

Co-authored-by: notCharles <charles@pelican.dev> Co-authored-by: Lance Pioch <lancepioch@gmail.com> Co-authored-by: Boy132 <mail@boy132.de> Co-authored-by: RMartinOscar <40749467+RMartinOscar@users.noreply.github.com>
67 lines
2.4 KiB
PHP
67 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Admin\Resources\WebhookResource\Pages;
|
|
|
|
use App\Filament\Admin\Resources\WebhookResource;
|
|
use App\Traits\Filament\CanCustomizeHeaderActions;
|
|
use App\Traits\Filament\CanCustomizeHeaderWidgets;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\ActionGroup;
|
|
use Filament\Resources\Pages\CreateRecord;
|
|
use App\Enums\WebhookType;
|
|
|
|
class CreateWebhookConfiguration extends CreateRecord
|
|
{
|
|
use CanCustomizeHeaderActions;
|
|
use CanCustomizeHeaderWidgets;
|
|
|
|
protected static string $resource = WebhookResource::class;
|
|
|
|
protected static bool $canCreateAnother = false;
|
|
|
|
/** @return array<Action|ActionGroup> */
|
|
protected function getDefaultHeaderActions(): array
|
|
{
|
|
return [
|
|
$this->getCancelFormAction()->formId('form'),
|
|
$this->getCreateFormAction()->formId('form'),
|
|
];
|
|
}
|
|
|
|
protected function getFormActions(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
protected function mutateFormDataBeforeCreate(array $data): array
|
|
{
|
|
if (($data['type'] ?? null) === WebhookType::Discord->value) {
|
|
$embeds = data_get($data, 'embeds', []);
|
|
|
|
foreach ($embeds as &$embed) {
|
|
$embed['color'] = hexdec(str_replace('#', '', data_get($embed, 'color')));
|
|
$embed = collect($embed)->filter(fn ($key) => is_array($key) ? array_filter($key, fn ($arr_key) => !empty($arr_key)) : !empty($key))->all();
|
|
}
|
|
|
|
$flags = collect($data['flags'] ?? [])->reduce(fn ($carry, $bit) => $carry | $bit, 0);
|
|
|
|
$tmp = collect([
|
|
'username' => data_get($data, 'username'),
|
|
'avatar_url' => data_get($data, 'avatar_url'),
|
|
'content' => data_get($data, 'content'),
|
|
'image' => data_get($data, 'image'),
|
|
'thumbnail' => data_get($data, 'thumbnail'),
|
|
'embeds' => $embeds,
|
|
'thread_name' => data_get($data, 'thread_name'),
|
|
'flags' => $flags,
|
|
'allowed_mentions' => data_get($data, 'allowed_mentions', []),
|
|
])->filter(fn ($key) => !empty($key))->all();
|
|
|
|
unset($data['username'], $data['avatar_url'], $data['content'], $data['image'], $data['thumbnail'], $data['embeds'], $data['thread_name'], $data['flags'], $data['allowed_mentions']);
|
|
$data['payload'] = $tmp;
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|