diff options
author | Joas Schilling <coding@schilljs.com> | 2018-08-01 10:56:22 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2018-08-01 10:56:22 +0200 |
commit | decd1961627986db094de4bf9b83589b9ccdb41e (patch) | |
tree | e8b5b830357c50d1bc2d3104322709bb97a76234 | |
parent | 3e0668e348a3935b76c915b8aa1e523caf8da921 (diff) | |
download | nextcloud-server-decd1961627986db094de4bf9b83589b9ccdb41e.tar.gz nextcloud-server-decd1961627986db094de4bf9b83589b9ccdb41e.zip |
Make the info available if the avatar was uploaded or generated
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | core/Controller/AvatarController.php | 11 | ||||
-rw-r--r-- | lib/private/Avatar.php | 11 | ||||
-rw-r--r-- | lib/public/IAvatar.php | 8 |
3 files changed, 24 insertions, 6 deletions
diff --git a/core/Controller/AvatarController.php b/core/Controller/AvatarController.php index 0625265dd05..03efe4d1e52 100644 --- a/core/Controller/AvatarController.php +++ b/core/Controller/AvatarController.php @@ -132,12 +132,13 @@ class AvatarController extends Controller { } try { - $avatar = $this->avatarManager->getAvatar($userId)->getFile($size); + $avatar = $this->avatarManager->getAvatar($userId); + $avatarFile = $avatar->getFile($size); $resp = new FileDisplayResponse( - $avatar, - Http::STATUS_OK, - ['Content-Type' => $avatar->getMimeType() - ]); + $avatarFile, + $avatar->isCustomAvatar() ? Http::STATUS_OK : Http::STATUS_CREATED, + ['Content-Type' => $avatarFile->getMimeType()] + ); } catch (\Exception $e) { $resp = new Http\Response(); $resp->setStatus(Http::STATUS_NOT_FOUND); diff --git a/lib/private/Avatar.php b/lib/private/Avatar.php index 9dbeb4ac745..116f8368e71 100644 --- a/lib/private/Avatar.php +++ b/lib/private/Avatar.php @@ -120,6 +120,15 @@ class Avatar implements IAvatar { } /** + * Check if the avatar of a user is a custom uploaded one + * + * @return bool + */ + public function isCustomAvatar(): bool { + return !$this->folder->fileExists('generated'); + } + + /** * sets the users avatar * @param IImage|resource|string $data An image object, imagedata or path to set a new avatar * @throws \Exception if the provided file is not a jpg or png image @@ -362,7 +371,7 @@ class Avatar implements IAvatar { * @param string $font font path * @param int $size font size * @param int $angle - * @return Array + * @return array */ protected function imageTTFCenter($image, string $text, string $font, int $size, $angle = 0): array { // Image width & height diff --git a/lib/public/IAvatar.php b/lib/public/IAvatar.php index 85863357069..448d5dfc02f 100644 --- a/lib/public/IAvatar.php +++ b/lib/public/IAvatar.php @@ -54,6 +54,14 @@ interface IAvatar { public function exists(); /** + * Check if the avatar of a user is a custom uploaded one + * + * @return bool + * @since 14.0.0 + */ + public function isCustomAvatar(): bool; + + /** * sets the users avatar * @param \OCP\IImage|resource|string $data An image object, imagedata or path to set a new avatar * @throws \Exception if the provided file is not a jpg or png image |