@@ -134,13 +134,23 @@ interface NormalizedRequest {
134134
135135/**
136136 * Normalizes the incoming request, such that we only work with UUIDs.
137- * Also returns the profile if it was fetched during username lookup (to avoid double lookups ).
137+ * Always fetches the profile to get the username (needed for text avatars and future skin support ).
138138 */
139139async function normalizeRequest ( incomingRequest : Request , request : CraftheadRequest ) : Promise < NormalizedRequest > {
140- if ( request . identityType === IdentityKind . Uuid || request . identityType === IdentityKind . TextureID ) {
140+ if ( request . identityType === IdentityKind . TextureID ) {
141141 return { request } ;
142142 }
143143
144+ if ( request . identityType === IdentityKind . Uuid ) {
145+ // UUID provided - fetch profile to get username
146+ const lookup = await hytaleApi . fetchProfile ( incomingRequest , request . identity ) ;
147+ if ( lookup . result ) {
148+ return { request, profile : lookup . result } ;
149+ }
150+ return { request } ;
151+ }
152+
153+ // Username provided - look up to get UUID and profile
144154 const normalized : CraftheadRequest = { ...request , identityType : IdentityKind . Uuid } ;
145155
146156 const profile = await hytaleApi . lookupUsername ( incomingRequest , request . identity ) ;
@@ -223,8 +233,13 @@ async function retrieveTextureDirect(
223233 * TEMPORARY: Renders a text-based avatar with username initials.
224234 * Replace with real skin rendering once Hytale skin support is implemented.
225235 */
226- export function renderAvatar ( request : CraftheadRequest ) : Response {
227- const imageData = render_text_avatar ( request . identity , request . size ) ;
236+ export async function renderAvatar ( incomingRequest : Request , request : CraftheadRequest ) : Promise < Response > {
237+ const { profile } = await normalizeRequest ( incomingRequest , request ) ;
238+
239+ // Use the username from profile if available, otherwise fall back to the original identity
240+ const username = profile ?. name ?? request . identity ;
241+
242+ const imageData = render_text_avatar ( username , request . size ) ;
228243 return new Response ( imageData , {
229244 headers : {
230245 'Content-Type' : 'image/png' ,
@@ -236,8 +251,8 @@ export function renderAvatar(request: CraftheadRequest): Response {
236251/**
237252 * TEMPORARY: Returns a text avatar since real Hytale skins aren't implemented yet.
238253 */
239- export function retrieveSkin ( _incomingRequest : Request , request : CraftheadRequest ) : Response {
240- return renderAvatar ( request ) ;
254+ export async function retrieveSkin ( incomingRequest : Request , request : CraftheadRequest ) : Promise < Response > {
255+ return renderAvatar ( incomingRequest , request ) ;
241256}
242257
243258/**
0 commit comments