Skip to content
Merged
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): allow guest avatar fallback
Signed-off-by: skjnldsv <[email protected]>
  • Loading branch information
skjnldsv authored and backportbot[bot] committed Jun 12, 2024
commit 4ad83e9fa327ed969138a94d2cfcfba98ff9f836
14 changes: 12 additions & 2 deletions core/Controller/AvatarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
use OCP\AppFramework\Http\DataDisplayResponse;
use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\IAvatarManager;
use OCP\ICache;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;

Expand All @@ -64,6 +66,8 @@ public function __construct(
protected LoggerInterface $logger,
protected ?string $userId,
protected TimeFactory $timeFactory,
protected IURLGenerator $urlGenerator,
protected GuestAvatarController $guestAvatarController,
) {
parent::__construct($appName, $request);
}
Expand All @@ -84,7 +88,7 @@ public function __construct(
* 404: Avatar not found
*/
#[FrontpageRoute(verb: 'GET', url: '/avatar/{userId}/{size}/dark')]
public function getAvatarDark(string $userId, int $size) {
public function getAvatarDark(string $userId, int $size, bool $guestFallback = false) {
if ($size <= 64) {
if ($size !== 64) {
$this->logger->debug('Avatar requested in deprecated size ' . $size);
Expand All @@ -106,6 +110,9 @@ public function getAvatarDark(string $userId, int $size) {
['Content-Type' => $avatarFile->getMimeType(), 'X-NC-IsCustomAvatar' => (int)$avatar->isCustomAvatar()]
);
} catch (\Exception $e) {
if ($guestFallback) {
return $this->guestAvatarController->getAvatarDark($userId, (string)$size);
}
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}

Expand All @@ -131,7 +138,7 @@ public function getAvatarDark(string $userId, int $size) {
* 404: Avatar not found
*/
#[FrontpageRoute(verb: 'GET', url: '/avatar/{userId}/{size}')]
public function getAvatar(string $userId, int $size) {
public function getAvatar(string $userId, int $size, bool $guestFallback = false) {
if ($size <= 64) {
if ($size !== 64) {
$this->logger->debug('Avatar requested in deprecated size ' . $size);
Expand All @@ -153,6 +160,9 @@ public function getAvatar(string $userId, int $size) {
['Content-Type' => $avatarFile->getMimeType(), 'X-NC-IsCustomAvatar' => (int)$avatar->isCustomAvatar()]
);
} catch (\Exception $e) {
if ($guestFallback) {
return $this->guestAvatarController->getAvatar($userId, (string)$size);
}
return new JSONResponse([], Http::STATUS_NOT_FOUND);
}

Expand Down