avatar actions

This commit is contained in:
robert dennis
2026-10-20 15:55:48 -04:00
parent f7aa208cab
commit a0a0bb99ab
19 changed files with 184 additions and 89 deletions
+17 -2
View File
@@ -22,7 +22,7 @@ use Pterodactyl\Facades\Activity;
use Pterodactyl\Models\Traits\HasAccessTokens;
use Pterodactyl\Models\Traits\HasRealtimeIdentifier;
use Pterodactyl\Notifications\SendPasswordReset as ResetPasswordNotification;
use Pterodactyl\Services\Users\UserAvatarService;
use Pterodactyl\Services\Extensions\ExtensionSettingFiles;
use Pterodactyl\Traits\Helpers\AvailableLanguages;
/**
@@ -66,6 +66,9 @@ class User extends Authenticatable implements Identifiable
public const string RESOURCE_NAME = 'user';
/** Avatars are stored with extension setting files under this id, which no extension may take. */
public const string AVATAR_FILES = 'user-avatars';
protected $attributes = [
'external_id' => null,
'root_admin' => false,
@@ -109,7 +112,7 @@ class User extends Authenticatable implements Identifiable
return [
...$attributes,
'avatar' => resolve(UserAvatarService::class)->url($this->avatar),
'avatar' => $this->avatar_url,
'identifier' => $this->identifier,
];
}
@@ -235,4 +238,16 @@ class User extends Authenticatable implements Identifiable
get: fn (): string => mb_trim($this->name_first.' '.$this->name_last),
);
}
/**
* Where the uploaded avatar is served from; null while the user has none.
*
* @return Attribute<string|null, never>
*/
protected function avatarUrl(): Attribute
{
return Attribute::make(
get: fn (): ?string => $this->avatar === null ? null : ExtensionSettingFiles::url(self::AVATAR_FILES, $this->avatar),
);
}
}