diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2016-08-29 14:55:23 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2016-08-30 09:00:16 +0200 |
commit | 14136295b7568c6e34504c101eba0ee10f5c74fd (patch) | |
tree | 8fa8c31163b4a4fc8621919f330f22e5631af385 /core/js | |
parent | c481210e2b24706f4cb0159bd82eb16ec58d9e92 (diff) | |
download | nextcloud-server-14136295b7568c6e34504c101eba0ee10f5c74fd.tar.gz nextcloud-server-14136295b7568c6e34504c101eba0ee10f5c74fd.zip |
Cache avatars properly
* Set proper caching headers for avatars (15 minutes)
* For our own avatar use some extra logic to invalidate when we update
Diffstat (limited to 'core/js')
-rw-r--r-- | core/js/config.php | 14 | ||||
-rw-r--r-- | core/js/jquery.avatar.js | 23 |
2 files changed, 30 insertions, 7 deletions
diff --git a/core/js/config.php b/core/js/config.php index e88d9c741a1..8e85dc91cb1 100644 --- a/core/js/config.php +++ b/core/js/config.php @@ -149,8 +149,8 @@ $array = array( "firstDay" => json_encode($l->l('firstday', null)) , "oc_config" => json_encode( array( - 'session_lifetime' => min(\OCP\Config::getSystemValue('session_lifetime', OC::$server->getIniWrapper()->getNumeric('session.gc_maxlifetime')), OC::$server->getIniWrapper()->getNumeric('session.gc_maxlifetime')), - 'session_keepalive' => \OCP\Config::getSystemValue('session_keepalive', true), + 'session_lifetime' => min($config->getSystemValue('session_lifetime', OC::$server->getIniWrapper()->getNumeric('session.gc_maxlifetime')), OC::$server->getIniWrapper()->getNumeric('session.gc_maxlifetime')), + 'session_keepalive' => $config->getSystemValue('session_keepalive', true), 'version' => implode('.', \OCP\Util::getVersion()), 'versionstring' => OC_Util::getVersionString(), 'enable_avatars' => \OC::$server->getConfig()->getSystemValue('enable_avatars', true) === true, @@ -187,9 +187,17 @@ $array = array( 'longFooter' => $defaults->getLongFooter(), 'folder' => OC_Util::getTheme(), ) - ) + ), ); +if (OC_User::getUser() !== null && OC_User::getUser() !== false) { + $array['oc_userconfig'] = json_encode([ + 'avatar' => [ + 'version' => (int)$config->getUserValue(OC_User::getUser(), 'avatar', 'version', 0), + ] + ]); +} + // Allow hooks to modify the output values OC_Hook::emit('\OCP\Config', 'js', array('array' => &$array)); diff --git a/core/js/jquery.avatar.js b/core/js/jquery.avatar.js index 6ae9cf78a13..754400acd7b 100644 --- a/core/js/jquery.avatar.js +++ b/core/js/jquery.avatar.js @@ -74,10 +74,25 @@ user = String(user).replace(/\//g,''); var $div = this; + var url; - var url = OC.generateUrl( - '/avatar/{user}/{size}', - {user: user, size: Math.ceil(size * window.devicePixelRatio)}); + // If this is our own avatar we have to use the version attribute + if (user === OC.getCurrentUser().uid) { + url = OC.generateUrl( + '/avatar/{user}/{size}?v={version}', + { + user: user, + size: Math.ceil(size * window.devicePixelRatio), + version: oc_userconfig.avatar.version + }); + } else { + url = OC.generateUrl( + '/avatar/{user}/{size}', + { + user: user, + size: Math.ceil(size * window.devicePixelRatio) + }); + } // If the displayname is not defined we use the old code path if (typeof(displayname) === 'undefined') { @@ -122,7 +137,7 @@ $div.show(); $div.text(''); $div.append(img); - } + }; img.width = size; img.height = size; |