mirror of
https://github.com/nextcloud/server.git
synced 2026-06-08 16:26:59 -04:00
fix(core): allow guest avatar fallback
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
This commit is contained in:
parent
a0a36563b6
commit
fb11672df6
1 changed files with 12 additions and 2 deletions
|
|
@ -14,12 +14,14 @@ use OCP\AppFramework\Http\Attribute\FrontpageRoute;
|
|||
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;
|
||||
|
||||
|
|
@ -40,6 +42,8 @@ class AvatarController extends Controller {
|
|||
protected LoggerInterface $logger,
|
||||
protected ?string $userId,
|
||||
protected TimeFactory $timeFactory,
|
||||
protected IURLGenerator $urlGenerator,
|
||||
protected GuestAvatarController $guestAvatarController,
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
}
|
||||
|
|
@ -60,7 +64,7 @@ class AvatarController extends Controller {
|
|||
* 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);
|
||||
|
|
@ -82,6 +86,9 @@ class AvatarController extends Controller {
|
|||
['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);
|
||||
}
|
||||
|
||||
|
|
@ -107,7 +114,7 @@ class AvatarController extends Controller {
|
|||
* 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);
|
||||
|
|
@ -129,6 +136,9 @@ class AvatarController extends Controller {
|
|||
['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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue