diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-06-15 16:16:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-15 16:16:13 +0200 |
commit | d82ef721611654aa3a3aab0ea3c8c85c7e0187d6 (patch) | |
tree | 2b75f2c5bad51beeec55f1da359a01abf1608048 /core | |
parent | a0496b2a7802d7605063056999ab0f3d465957af (diff) | |
parent | 543188d0cb2f03e661ba937dcef5f56f739ea582 (diff) | |
download | nextcloud-server-d82ef721611654aa3a3aab0ea3c8c85c7e0187d6.tar.gz nextcloud-server-d82ef721611654aa3a3aab0ea3c8c85c7e0187d6.zip |
Merge pull request #9197 from nextcloud/fix-avatar-center
Fix avatar generator centering
Diffstat (limited to 'core')
-rw-r--r-- | core/Controller/AvatarController.php | 11 | ||||
-rw-r--r-- | core/js/placeholder.js | 9 |
2 files changed, 13 insertions, 7 deletions
diff --git a/core/Controller/AvatarController.php b/core/Controller/AvatarController.php index 11d81ab00b2..0625265dd05 100644 --- a/core/Controller/AvatarController.php +++ b/core/Controller/AvatarController.php @@ -8,6 +8,7 @@ * @author Roeland Jago Douma <roeland@famdouma.nl> * @author Thomas Müller <thomas.mueller@tmit.eu> * @author Vincent Petry <pvince81@owncloud.com> + * @author John Molakvoæ <skjnldsv@protonmail.com> * * @license AGPL-3.0 * @@ -41,6 +42,7 @@ use OCP\IL10N; use OCP\IRequest; use OCP\IUserManager; use OCP\IUserSession; +use OCP\AppFramework\Http\DataResponse; /** * Class AvatarController @@ -111,8 +113,6 @@ class AvatarController extends Controller { } - - /** * @NoAdminRequired * @NoCSRFRequired @@ -124,6 +124,7 @@ class AvatarController extends Controller { * @return JSONResponse|FileDisplayResponse */ public function getAvatar($userId, $size) { + // min/max size if ($size > 2048) { $size = 2048; } elseif ($size <= 0) { @@ -132,9 +133,11 @@ class AvatarController extends Controller { try { $avatar = $this->avatarManager->getAvatar($userId)->getFile($size); - $resp = new FileDisplayResponse($avatar, + $resp = new FileDisplayResponse( + $avatar, Http::STATUS_OK, - ['Content-Type' => $avatar->getMimeType()]); + ['Content-Type' => $avatar->getMimeType() + ]); } catch (\Exception $e) { $resp = new Http\Response(); $resp->setStatus(Http::STATUS_NOT_FOUND); diff --git a/core/js/placeholder.js b/core/js/placeholder.js index a0dfe8491d4..81f0b12e61a 100644 --- a/core/js/placeholder.js +++ b/core/js/placeholder.js @@ -62,13 +62,16 @@ (function ($) { String.prototype.toRgb = function() { - var hash = this.toLowerCase().replace(/[^0-9a-f]+/g, ''); + // Normalize hash + var hash = this.toLowerCase(); // Already a md5 hash? - if( !hash.match(/^[0-9a-f]{32}$/g) ) { + if( hash.match(/^([0-9a-f]{4}-?){8}$/) === null ) { hash = md5(hash); } + hash = hash.replace(/[^0-9a-f]/g, ''); + function Color(r,g,b) { this.r = r; this.g = g; @@ -116,7 +119,7 @@ var result = Array(); // Splitting evenly the string - for (var i in hash) { + for (var i=0; i<hash.length; i++) { // chars in md5 goes up to f, hex:16 result.push(parseInt(hash.charAt(i), 16) % 16); } |