Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ Download `user-avatars-${VERSION}.pteroext` below, then either upload it under *
php artisan p:extension:install /path/to/user-avatars-${VERSION}.pteroext --enable
```

Requires Pterodactyl Panel 2.0 (2.0-develop or later) and PHP 8.3+.
Requires Pterodactyl Panel v2.0.0-beta.1 or later and PHP 8.3+.

This is a community extension and is not affiliated with or endorsed by Pterodactyl.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 3.2.0

- Works with Pterodactyl v2.0.0-beta.1 (SDK beta.6).
- The beta removed the user transformers this extension replaced, so pictures had fallen back to Gravatar in admin lists, subusers and activity. Pictures are now put into the panel's API responses directly.

## 3.1.0

- Activity rows with no user behind them (failed logins, scheduled tasks) show a plain system icon instead of a generated pattern.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Let users upload their own profile picture, shown in the navigation bar, admin u

Pterodactyl 2.0 has no avatar uploads. Core draws a generated pattern in the navigation bar and loads Gravatar images in admin and subuser lists. This extension replaces both with the user's upload or the default picture.

- Lists that show a user's `image` (admin users, server owner, subusers) get the user's picture because this extension replaces the panel's user transformers with versions that swap in the uploaded URL. If another extension also replaces `Pterodactyl\Transformers\Api\Client\UserTransformer` or `Pterodactyl\Transformers\Api\Admin\UserTransformer`, only one of them will win.
- Lists that show a user's `image` (admin users, server owner, subusers, activity) get the user's picture because the extension swaps the uploaded or default picture into the panel's API responses as they go out. The panel's own user resources cannot be replaced in v2.0.0-beta.1, so this is done after the response is built.
- The navigation bar avatar is not a replaceable component in 2.0, so the user's picture is laid over it with CSS that targets the "Account Settings" link. A panel update that changes that link could break it; the rest of the extension is unaffected.
- Activity rows draw a generated avatar from the username and are not replaceable either. The activity API already includes each actor's picture, so the extension matches rows to it by username and lays the picture over the generated avatar. Rows with no user (shown as "System") get the picture set in the extension's **System picture** setting, or a plain system icon when none is set. A panel update that changes the activity row layout could break it.

Expand All @@ -29,7 +29,7 @@ Pterodactyl 2.0 has no avatar uploads. Core draws a generated pattern in the nav

## Requirements

- Pterodactyl Panel 2.0 (2.0-develop or later)
- Pterodactyl Panel v2.0.0-beta.1 or later
- PHP 8.3+ (the GD extension is recommended; without it only PNG, JPEG and WebP are accepted and stored as uploaded)

## Install
Expand Down
4 changes: 2 additions & 2 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"$schema": "./node_modules/@pterodactyl/sdk/manifest.schema.json",
"id": "user-avatars",
"name": "User Avatars",
"version": "3.1.0",
"version": "3.2.0",
"description": "Let users upload their own profile picture, shown in the navigation bar, admin user lists, server subuser lists and activity logs.",
"author": "RustixDev",
"icon": "circle-user",
"requires": {
"panel": "^2.0.0-dev",
"sdk": ">=2.0.0-beta.4 <3.0",
"sdk": ">=2.0.0-beta.6 <3.0",
"php": "^8.3"
},
"provider": "UserAvatars\\UserAvatarsProvider",
Expand Down
15 changes: 9 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "user-avatars",
"private": true,
"version": "3.1.0",
"version": "3.2.0",
"type": "module",
"scripts": {
"build": "vite build",
Expand All @@ -11,7 +11,7 @@
"test:watch": "vitest"
},
"devDependencies": {
"@pterodactyl/sdk": "file:./sdk/pterodactyl-sdk-2.0.0-beta.4.tgz",
"@pterodactyl/sdk": "file:./sdk/pterodactyl-sdk-2.0.0-beta.6.tgz",
"@tanstack/react-query": "^5",
"@base-ui/react": "^1.6.0",
"@tanstack/form-core": "^1.33.0",
Expand Down
2 changes: 1 addition & 1 deletion sdk/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Pterodactyl SDK

`@pterodactyl/sdk` is not published to npm yet. This tarball was built with `npm pack` in `packages/sdk` of [pterodactyl/panel](https://github.com/pterodactyl/panel) on the `2.0-develop` branch, commit `a86da61` (2026-10-09). The SDK is MIT licensed by Pterodactyl.
`@pterodactyl/sdk` is not published to npm yet. This tarball was built with `npm pack` in `packages/sdk` of [pterodactyl/panel](https://github.com/pterodactyl/panel) on the `2.0-develop` branch, commit `ba6ab9b` (2026-10-13), version `2.0.0-beta.6`. The SDK is MIT licensed by Pterodactyl.

To update it, run `npm pack` in a newer panel checkout's `packages/sdk`, replace the tarball here and update the path in `package.json`.
Binary file removed sdk/pterodactyl-sdk-2.0.0-beta.4.tgz
Binary file not shown.
Binary file added sdk/pterodactyl-sdk-2.0.0-beta.6.tgz
Binary file not shown.
85 changes: 85 additions & 0 deletions src/Http/UserImages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace UserAvatars\Http;

use Illuminate\Foundation\Http\Events\RequestHandled;
use Illuminate\Http\JsonResponse;
use Pterodactyl\Models\User;
use UserAvatars\Services\AvatarService;

/**
* The panel's API resources build a user's "image" themselves and cannot be replaced,
* so API responses are patched on the way out: every user (admin users, a server's
* owner, subusers, activity actors) gets the uploaded or default picture.
*/
class UserImages
{
/** Objects whose attributes are a user's, "image" included (subusers carry their user's). */
private const array OBJECTS = ['user', 'server_subuser'];

public function __construct(private readonly AvatarService $avatars) {}

public function handle(RequestHandled $event): void
{
$response = $event->response;

if (! $response instanceof JsonResponse || ! $event->request->is('api/*')) {
return;
}

$content = (string) $response->getContent();
if (! str_contains($content, '"image"')) {
return;
}

$data = $response->getData();
$users = [];
$this->collect($data, $users);

if ($users === []) {
return;
}

$ids = User::query()->whereIn('uuid', array_keys($users))->pluck('id', 'uuid');

foreach ($users as $uuid => $attributes) {
if (! isset($ids[$uuid])) {
continue;
}

$url = $this->avatars->urlFor((int) $ids[$uuid], $uuid);
foreach ($attributes as $object) {
$object->image = $url;
}
}

$response->setData($data);
}

/** @param array<string, list<object>> $users uuid => attribute objects to update */
private function collect(mixed $node, array &$users): void
{
if (is_array($node)) {
foreach ($node as $child) {
$this->collect($child, $users);
}

return;
}

if (! is_object($node)) {
return;
}

if (in_array($node->object ?? null, self::OBJECTS, true) && isset($node->attributes) && is_object($node->attributes)) {
$attributes = $node->attributes;
if (is_string($attributes->uuid ?? null) && property_exists($attributes, 'image')) {
$users[$attributes->uuid][] = $attributes;
}
}

foreach (get_object_vars($node) as $child) {
$this->collect($child, $users);
}
}
}
9 changes: 7 additions & 2 deletions src/Services/AvatarService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ public function hasUpload(User $user): bool
/** The URL core components put in <img src>. They append "?s=<size>", so it must take a query string. */
public function url(User $user): string
{
$token = $this->tokens()[$user->id] ?? null;
return $this->urlFor($user->id, $user->uuid);
}

public function urlFor(int $id, string $uuid): string
{
$token = $this->tokens()[$id] ?? null;

if ($token !== null) {
return url('/extensions/user-avatars/a/'.$token);
}

return url('/extensions/user-avatars/d/'.$user->uuid);
return url('/extensions/user-avatars/d/'.$uuid);
}

public function store(User $user, UploadedFile $file): Avatar
Expand Down
15 changes: 0 additions & 15 deletions src/Transformers/AdminUserTransformer.php

This file was deleted.

15 changes: 0 additions & 15 deletions src/Transformers/ClientUserTransformer.php

This file was deleted.

15 changes: 6 additions & 9 deletions src/UserAvatarsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
use Pterodactyl\Services\Extensions\ExtensionSettingDefinition;
use Pterodactyl\Services\Extensions\ExtensionSettingFiles;
use Pterodactyl\Services\Extensions\ExtensionSettingsDefinition;
use Pterodactyl\Transformers\Api\Admin\UserTransformer as CoreAdminUserTransformer;
use Pterodactyl\Transformers\Api\Client\UserTransformer as CoreClientUserTransformer;
use Illuminate\Foundation\Http\Events\RequestHandled;
use Illuminate\Support\Facades\Event;
use UserAvatars\Http\UserImages;
use UserAvatars\Services\AvatarService;
use UserAvatars\Transformers\AdminUserTransformer;
use UserAvatars\Transformers\ClientUserTransformer;

class UserAvatarsProvider extends ExtensionProvider
{
Expand All @@ -35,10 +34,8 @@ public function boot(): void

$this->app->scoped(AvatarService::class, fn () => new AvatarService($this->settings()));

// Core user transformers are resolved through the container, so every API
// response that includes a user's "image" (admin user list, server owner,
// subusers) picks up the uploaded avatar.
$this->app->bind(CoreClientUserTransformer::class, ClientUserTransformer::class);
$this->app->bind(CoreAdminUserTransformer::class, AdminUserTransformer::class);
// Every API response that includes a user's "image" (admin user list, server
// owner, subusers, activity) gets the uploaded or default picture.
Event::listen(RequestHandled::class, [UserImages::class, 'handle']);
}
}
Loading