From c8e767878d3deac29db18c56896e519dbf17980c Mon Sep 17 00:00:00 2001 From: provokateurin Date: Fri, 7 Jun 2024 12:09:36 +0200 Subject: fix(core): Return X-NC-IsCustomAvatar for guest avatars too Signed-off-by: provokateurin --- core/Controller/AvatarController.php | 6 +- core/Controller/GuestAvatarController.php | 6 +- core/openapi.json | 102 ++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 5 deletions(-) diff --git a/core/Controller/AvatarController.php b/core/Controller/AvatarController.php index f65281602bd..f29c9c5ab4f 100644 --- a/core/Controller/AvatarController.php +++ b/core/Controller/AvatarController.php @@ -57,9 +57,10 @@ class AvatarController extends Controller { * @param string $userId ID of the user * @param int $size Size of the avatar * @param bool $guestFallback Fallback to guest avatar if not found - * @return FileDisplayResponse|JSONResponse, array{}>|Response + * @return FileDisplayResponse|JSONResponse, array{}>|Response * * 200: Avatar returned + * 201: Avatar returned * 404: Avatar not found */ #[FrontpageRoute(verb: 'GET', url: '/avatar/{userId}/{size}/dark')] @@ -108,9 +109,10 @@ class AvatarController extends Controller { * @param string $userId ID of the user * @param int $size Size of the avatar * @param bool $guestFallback Fallback to guest avatar if not found - * @return FileDisplayResponse|JSONResponse, array{}>|Response + * @return FileDisplayResponse|JSONResponse, array{}>|Response * * 200: Avatar returned + * 201: Avatar returned * 404: Avatar not found */ #[FrontpageRoute(verb: 'GET', url: '/avatar/{userId}/{size}')] diff --git a/core/Controller/GuestAvatarController.php b/core/Controller/GuestAvatarController.php index a2148e5d8c1..3121abc2ca1 100644 --- a/core/Controller/GuestAvatarController.php +++ b/core/Controller/GuestAvatarController.php @@ -39,7 +39,7 @@ class GuestAvatarController extends Controller { * @param string $guestName The guest name, e.g. "Albert" * @param string $size The desired avatar size, e.g. 64 for 64x64px * @param bool|null $darkTheme Return dark avatar - * @return FileDisplayResponse|Response + * @return FileDisplayResponse|Response * * 200: Custom avatar returned * 201: Avatar returned @@ -68,7 +68,7 @@ class GuestAvatarController extends Controller { $resp = new FileDisplayResponse( $avatarFile, $avatar->isCustomAvatar() ? Http::STATUS_OK : Http::STATUS_CREATED, - ['Content-Type' => $avatarFile->getMimeType()] + ['Content-Type' => $avatarFile->getMimeType(), 'X-NC-IsCustomAvatar' => (int)$avatar->isCustomAvatar()] ); } catch (\Exception $e) { $this->logger->error('error while creating guest avatar', [ @@ -92,7 +92,7 @@ class GuestAvatarController extends Controller { * * @param string $guestName The guest name, e.g. "Albert" * @param string $size The desired avatar size, e.g. 64 for 64x64px - * @return FileDisplayResponse|Response + * @return FileDisplayResponse|Response * * 200: Custom avatar returned * 201: Avatar returned diff --git a/core/openapi.json b/core/openapi.json index e47819c19be..3bb74224fa1 100644 --- a/core/openapi.json +++ b/core/openapi.json @@ -7318,6 +7318,19 @@ } ], "parameters": [ + { + "name": "guestFallback", + "in": "query", + "description": "Fallback to guest avatar if not found", + "schema": { + "type": "integer", + "default": 0, + "enum": [ + 0, + 1 + ] + } + }, { "name": "userId", "in": "path", @@ -7358,6 +7371,25 @@ } } }, + "201": { + "description": "Avatar returned", + "headers": { + "X-NC-IsCustomAvatar": { + "schema": { + "type": "integer", + "format": "int64" + } + } + }, + "content": { + "*/*": { + "schema": { + "type": "string", + "format": "binary" + } + } + } + }, "404": { "description": "Avatar not found", "content": { @@ -7365,6 +7397,9 @@ "schema": {} } } + }, + "500": { + "description": "" } } } @@ -7386,6 +7421,19 @@ } ], "parameters": [ + { + "name": "guestFallback", + "in": "query", + "description": "Fallback to guest avatar if not found", + "schema": { + "type": "integer", + "default": 0, + "enum": [ + 0, + 1 + ] + } + }, { "name": "userId", "in": "path", @@ -7426,6 +7474,25 @@ } } }, + "201": { + "description": "Avatar returned", + "headers": { + "X-NC-IsCustomAvatar": { + "schema": { + "type": "integer", + "format": "int64" + } + } + }, + "content": { + "*/*": { + "schema": { + "type": "string", + "format": "binary" + } + } + } + }, "404": { "description": "Avatar not found", "content": { @@ -7433,6 +7500,9 @@ "schema": {} } } + }, + "500": { + "description": "" } } } @@ -7569,6 +7639,14 @@ "responses": { "200": { "description": "Custom avatar returned", + "headers": { + "X-NC-IsCustomAvatar": { + "schema": { + "type": "integer", + "format": "int64" + } + } + }, "content": { "*/*": { "schema": { @@ -7580,6 +7658,14 @@ }, "201": { "description": "Avatar returned", + "headers": { + "X-NC-IsCustomAvatar": { + "schema": { + "type": "integer", + "format": "int64" + } + } + }, "content": { "*/*": { "schema": { @@ -7634,6 +7720,14 @@ "responses": { "200": { "description": "Custom avatar returned", + "headers": { + "X-NC-IsCustomAvatar": { + "schema": { + "type": "integer", + "format": "int64" + } + } + }, "content": { "*/*": { "schema": { @@ -7645,6 +7739,14 @@ }, "201": { "description": "Avatar returned", + "headers": { + "X-NC-IsCustomAvatar": { + "schema": { + "type": "integer", + "format": "int64" + } + } + }, "content": { "*/*": { "schema": { -- cgit v1.2.3