Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(core): Return X-NC-IsCustomAvatar for guest avatars too
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin authored and backportbot[bot] committed Jun 12, 2024
commit ac4ead61af74c3bf61a94730a175a5380c9c5b00
6 changes: 4 additions & 2 deletions core/Controller/AvatarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ public function __construct(
* @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<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar?: int}>|JSONResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}>
* @return FileDisplayResponse<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar: int}>|JSONResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}>
*
* 200: Avatar returned
* 201: Avatar returned
* 404: Avatar not found
*/
#[FrontpageRoute(verb: 'GET', url: '/avatar/{userId}/{size}/dark')]
Expand Down Expand Up @@ -132,9 +133,10 @@ public function getAvatarDark(string $userId, int $size, bool $guestFallback = f
* @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<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar?: int}>|JSONResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}>
* @return FileDisplayResponse<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar: int}>|JSONResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}>
*
* 200: Avatar returned
* 201: Avatar returned
* 404: Avatar not found
*/
#[FrontpageRoute(verb: 'GET', url: '/avatar/{userId}/{size}')]
Expand Down
6 changes: 3 additions & 3 deletions core/Controller/GuestAvatarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(
* @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<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}>
* @return FileDisplayResponse<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar: int}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}>
*
* 200: Custom avatar returned
* 201: Avatar returned
Expand Down Expand Up @@ -86,7 +86,7 @@ public function getAvatar(string $guestName, string $size, ?bool $darkTheme = fa
$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', [
Expand All @@ -110,7 +110,7 @@ public function getAvatar(string $guestName, string $size, ?bool $darkTheme = fa
*
* @param string $guestName The guest name, e.g. "Albert"
* @param string $size The desired avatar size, e.g. 64 for 64x64px
* @return FileDisplayResponse<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}>
* @return FileDisplayResponse<Http::STATUS_OK|Http::STATUS_CREATED, array{Content-Type: string, X-NC-IsCustomAvatar: int}>|Response<Http::STATUS_INTERNAL_SERVER_ERROR, array{}>
*
* 200: Custom avatar returned
* 201: Avatar returned
Expand Down
102 changes: 102 additions & 0 deletions core/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -5677,6 +5677,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",
Expand Down Expand Up @@ -5717,13 +5730,35 @@
}
}
},
"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": {
"application/json": {
"schema": {}
}
}
},
"500": {
"description": ""
}
}
}
Expand All @@ -5745,6 +5780,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",
Expand Down Expand Up @@ -5785,13 +5833,35 @@
}
}
},
"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": {
"application/json": {
"schema": {}
}
}
},
"500": {
"description": ""
}
}
}
Expand Down Expand Up @@ -5928,6 +5998,14 @@
"responses": {
"200": {
"description": "Custom avatar returned",
"headers": {
"X-NC-IsCustomAvatar": {
"schema": {
"type": "integer",
"format": "int64"
}
}
},
"content": {
"*/*": {
"schema": {
Expand All @@ -5939,6 +6017,14 @@
},
"201": {
"description": "Avatar returned",
"headers": {
"X-NC-IsCustomAvatar": {
"schema": {
"type": "integer",
"format": "int64"
}
}
},
"content": {
"*/*": {
"schema": {
Expand Down Expand Up @@ -5993,6 +6079,14 @@
"responses": {
"200": {
"description": "Custom avatar returned",
"headers": {
"X-NC-IsCustomAvatar": {
"schema": {
"type": "integer",
"format": "int64"
}
}
},
"content": {
"*/*": {
"schema": {
Expand All @@ -6004,6 +6098,14 @@
},
"201": {
"description": "Avatar returned",
"headers": {
"X-NC-IsCustomAvatar": {
"schema": {
"type": "integer",
"format": "int64"
}
}
},
"content": {
"*/*": {
"schema": {
Expand Down