diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-05-05 18:17:09 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-06-13 18:46:04 +0200 |
commit | adf3856d35945790fed5f7934d8c154d1f01b377 (patch) | |
tree | 6ae1b9220936a0dd236a3e58cd7eed189352cfc1 /core | |
parent | 8e3382cedaecf551c3d6991feae08c57f66496eb (diff) | |
download | nextcloud-server-adf3856d35945790fed5f7934d8c154d1f01b377.tar.gz nextcloud-server-adf3856d35945790fed5f7934d8c154d1f01b377.zip |
Return Svg avatars
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'core')
-rw-r--r-- | core/Controller/AvatarController.php | 46 | ||||
-rw-r--r-- | core/routes.php | 1 |
2 files changed, 38 insertions, 9 deletions
diff --git a/core/Controller/AvatarController.php b/core/Controller/AvatarController.php index 11d81ab00b2..6f0cf03d8e8 100644 --- a/core/Controller/AvatarController.php +++ b/core/Controller/AvatarController.php @@ -41,6 +41,7 @@ use OCP\IL10N; use OCP\IRequest; use OCP\IUserManager; use OCP\IUserSession; +use OCP\AppFramework\Http\DataResponse; /** * Class AvatarController @@ -113,6 +114,20 @@ class AvatarController extends Controller { + + /** + * @NoAdminRequired + * @NoCSRFRequired + * @NoSameSiteCookieRequired + * @PublicPage + * + * Shortcut to getAvatar + */ + public function getAvatarPng($userId, $size) { + return $this->getAvatar($userId, $size, true); + } + + /** * @NoAdminRequired * @NoCSRFRequired @@ -121,24 +136,37 @@ class AvatarController extends Controller { * * @param string $userId * @param int $size + * @param bool $png return png or not * @return JSONResponse|FileDisplayResponse */ - public function getAvatar($userId, $size) { + public function getAvatar($userId, $size, bool $png = false) { if ($size > 2048) { $size = 2048; } elseif ($size <= 0) { $size = 64; } - try { - $avatar = $this->avatarManager->getAvatar($userId)->getFile($size); - $resp = new FileDisplayResponse($avatar, + if ($png === false) { + $avatar = $this->avatarManager->getAvatar($userId)->getAvatarVector($size); + $resp = new DataDisplayResponse( + $avatar, Http::STATUS_OK, - ['Content-Type' => $avatar->getMimeType()]); - } catch (\Exception $e) { - $resp = new Http\Response(); - $resp->setStatus(Http::STATUS_NOT_FOUND); - return $resp; + ['Content-Type' => 'image/svg+xml' + ]); + } else { + + try { + $avatar = $this->avatarManager->getAvatar($userId)->getFile($size); + $resp = new FileDisplayResponse( + $avatar, + Http::STATUS_OK, + ['Content-Type' => $avatar->getMimeType() + ]); + } catch (\Exception $e) { + $resp = new Http\Response(); + $resp->setStatus(Http::STATUS_NOT_FOUND); + return $resp; + } } // Cache for 30 minutes diff --git a/core/routes.php b/core/routes.php index cc1bd34d898..dd35638a7ee 100644 --- a/core/routes.php +++ b/core/routes.php @@ -42,6 +42,7 @@ $application->registerRoutes($this, [ ['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'], ['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'], ['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'], + ['name' => 'avatar#getAvatarPng', 'url' => '/avatar/{userId}/{size}/png', 'verb' => 'GET'], ['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'], ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'], ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'], |