diff --git a/.github/release-notes.md b/.github/release-notes.md index 2e51d65..78c3883 100644 --- a/.github/release-notes.md +++ b/.github/release-notes.md @@ -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. diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d54a8f..2a80bd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/README.md b/README.md index 0995891..f270a22 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/extension.json b/extension.json index ea4c6bd..6187b4c 100644 --- a/extension.json +++ b/extension.json @@ -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", diff --git a/package-lock.json b/package-lock.json index e2833f1..35c3216 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "user-avatars", - "version": "3.1.0", + "version": "3.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "user-avatars", - "version": "3.1.0", + "version": "3.2.0", "devDependencies": { "@base-ui/react": "^1.6.0", - "@pterodactyl/sdk": "file:./sdk/pterodactyl-sdk-2.0.0-beta.4.tgz", + "@pterodactyl/sdk": "file:./sdk/pterodactyl-sdk-2.0.0-beta.6.tgz", "@tailwindcss/postcss": "^4", "@tanstack/form-core": "^1.33.0", "@tanstack/react-form": "^1.33.0", @@ -372,11 +372,14 @@ } }, "node_modules/@pterodactyl/sdk": { - "version": "2.0.0-beta.4", - "resolved": "file:./sdk/pterodactyl-sdk-2.0.0-beta.4.tgz", - "integrity": "sha512-y+TzpLNngphgOkSvWW9u8b9TF8e83zhyzLOmgIF/KJiyy+gtYk6Kr0cIUgL1T43ezbYfZSTwBrDMGb440uAHig==", + "version": "2.0.0-beta.6", + "resolved": "file:sdk/pterodactyl-sdk-2.0.0-beta.6.tgz", + "integrity": "sha512-tatI71EZd71b1HPIKwwxV+30OgkoqyjiCNBM2xTSGPgdxFHbrvH8fi4EBYSSjgalsmj0etsVA/mBZuKU2CG1qg==", "dev": true, "license": "MIT", + "bin": { + "pterodactyl-theme": "bin/pterodactyl-theme.mjs" + }, "peerDependencies": { "@base-ui/react": "^1.6.0", "@tanstack/form-core": "^1.33.0", diff --git a/package.json b/package.json index 3568f8a..bca7cc7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "user-avatars", "private": true, - "version": "3.1.0", + "version": "3.2.0", "type": "module", "scripts": { "build": "vite build", @@ -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", diff --git a/sdk/README.md b/sdk/README.md index ea235c5..37ebc17 100644 --- a/sdk/README.md +++ b/sdk/README.md @@ -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`. diff --git a/sdk/pterodactyl-sdk-2.0.0-beta.4.tgz b/sdk/pterodactyl-sdk-2.0.0-beta.4.tgz deleted file mode 100644 index 78dd503..0000000 Binary files a/sdk/pterodactyl-sdk-2.0.0-beta.4.tgz and /dev/null differ diff --git a/sdk/pterodactyl-sdk-2.0.0-beta.6.tgz b/sdk/pterodactyl-sdk-2.0.0-beta.6.tgz new file mode 100644 index 0000000..64f4555 Binary files /dev/null and b/sdk/pterodactyl-sdk-2.0.0-beta.6.tgz differ diff --git a/src/Http/UserImages.php b/src/Http/UserImages.php new file mode 100644 index 0000000..b240697 --- /dev/null +++ b/src/Http/UserImages.php @@ -0,0 +1,85 @@ +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> $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); + } + } +} diff --git a/src/Services/AvatarService.php b/src/Services/AvatarService.php index 3f6a22d..c006a16 100644 --- a/src/Services/AvatarService.php +++ b/src/Services/AvatarService.php @@ -35,13 +35,18 @@ public function hasUpload(User $user): bool /** The URL core components put in . They append "?s=", 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 diff --git a/src/Transformers/AdminUserTransformer.php b/src/Transformers/AdminUserTransformer.php deleted file mode 100644 index 6507e01..0000000 --- a/src/Transformers/AdminUserTransformer.php +++ /dev/null @@ -1,15 +0,0 @@ - app(AvatarService::class)->url($user)] + parent::transform($user); - } -} diff --git a/src/Transformers/ClientUserTransformer.php b/src/Transformers/ClientUserTransformer.php deleted file mode 100644 index 35d5953..0000000 --- a/src/Transformers/ClientUserTransformer.php +++ /dev/null @@ -1,15 +0,0 @@ - app(AvatarService::class)->url($model)] + parent::transform($model); - } -} diff --git a/src/UserAvatarsProvider.php b/src/UserAvatarsProvider.php index 2f22715..e10d576 100644 --- a/src/UserAvatarsProvider.php +++ b/src/UserAvatarsProvider.php @@ -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 { @@ -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']); } }