Files
pterodactyl-panel/app/Http/ViewComposers/AssetComposer.php
T
ItzLinaton 60b72365d8 Feat: Custom User Avatars (V2) (#7295)
Added custom user avatar support.

## Extra Details:
- Users can upload custom `PNG, JPEG, SVG, WebP, AVIF`, and `ICO`
avatars.
- Added avatar management to the user account area.
- Added admin controls to update and remove user avatars.
- Custom User avatars appear in:
  - Panel Navbar.
  - Panel Admin Activity Logs.
  - Server Sub user List.
  - Server Activity Logs
  - Personal Account Activity Logs.
  - Server Ownership Details.
  
---

<img width="1329" height="327"
alt="{B32EBD7F-1FCA-4356-966C-0D60A9A23E49}"
src="https://github.com/user-attachments/assets/881fa5b3-9599-4370-975d-83b6bd91a7d1"
/>

---

<img width="997" height="847" alt="adminpage"
src="https://github.com/user-attachments/assets/989acbcc-351c-431b-ab7f-557ba4c7e070"
/>

---

<img width="955" height="781" alt="serverinfo"
src="https://github.com/user-attachments/assets/6556afac-1971-4112-9686-b71137072c5f"
/>

---

<img width="1376" height="919" alt="userarea"
src="https://github.com/user-attachments/assets/d49f0ddb-1f38-4884-b186-8db78bfed4b0"
/>

---

<img width="936" height="232" alt="userslist"
src="https://github.com/user-attachments/assets/0e8a4b4a-719a-4d52-a485-d7577736b43f"
/>

---

<img width="983" height="772" alt="activity"
src="https://github.com/user-attachments/assets/37ef7176-a804-43f7-ae32-ae65e1a2671b"
/>
2026-10-20 15:09:33 -04:00

76 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Pterodactyl\Http\ViewComposers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use Pterodactyl\Services\Extensions\ExtensionHeadTags;
use Pterodactyl\Services\Extensions\ExtensionRepository;
use Pterodactyl\Services\Helpers\AssetHashService;
use Pterodactyl\Services\Themes\ThemeResolver;
use Throwable;
class AssetComposer
{
/**
* AssetComposer constructor.
*/
public function __construct(
private readonly AssetHashService $assetHashService,
private readonly ExtensionRepository $extensions,
private readonly ExtensionHeadTags $extensionHeadTags,
private readonly ThemeResolver $themes,
private readonly Request $request,
) {}
/**
* Provide access to the asset service in the views.
*/
public function compose(View $view): void
{
$theme = $this->themes->document($this->request);
$view->with('asset', $this->assetHashService);
// Rendered lazily by the layout; resolving the tags never throws.
$view->with('extensionHead', $this->extensionHeadTags);
$view->with('theme', $theme);
$view->with('siteConfiguration', [
'name' => config('app.name', 'Pterodactyl'),
'locale' => config('app.locale', 'en'),
'userAvatarsEnabled' => config('pterodactyl.client_features.avatars.enabled', false),
'recaptcha' => [
'enabled' => config('recaptcha.enabled', false),
'siteKey' => config('recaptcha.website_key', ''),
],
// Safe mode loads no extension bundles at all.
'extensions' => $theme->safeMode ? [] : $this->extensionPayload(array_column($theme->chain, 'id')),
'theme' => $theme->bootstrap(),
]);
}
/**
* The enabled frontend extensions the SPA boot loader should import, with their
* frontend settings for signed-in users and only the public ones for guests, and
* the themes of the chain the page renders with. Never allowed to break page
* rendering - worst case the SPA sees no extensions.
*
* @param list<string> $themes
* @return array<int, array{id: string, version?: string, entry: string}>
*/
private function extensionPayload(array $themes): array
{
if (! config('extensions.enabled')) {
return [];
}
try {
return $this->extensions->frontendPayload(authenticated: Auth::check(), themes: $themes);
} catch (Throwable) {
return [];
}
}
}