summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2016-08-29 14:55:23 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-08-30 09:00:16 +0200
commit14136295b7568c6e34504c101eba0ee10f5c74fd (patch)
tree8fa8c31163b4a4fc8621919f330f22e5631af385 /lib/private
parentc481210e2b24706f4cb0159bd82eb16ec58d9e92 (diff)
downloadnextcloud-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 'lib/private')
-rw-r--r--lib/private/Avatar.php14
-rw-r--r--lib/private/AvatarManager.php11
-rw-r--r--lib/private/Server.php3
-rw-r--r--lib/private/TemplateLayout.php1
4 files changed, 25 insertions, 4 deletions
diff --git a/lib/private/Avatar.php b/lib/private/Avatar.php
index 80691774b64..9e8bd0136c2 100644
--- a/lib/private/Avatar.php
+++ b/lib/private/Avatar.php
@@ -34,6 +34,7 @@ use OCP\Files\File;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\IAvatar;
+use OCP\IConfig;
use OCP\IImage;
use OCP\IL10N;
use OC_Image;
@@ -52,6 +53,8 @@ class Avatar implements IAvatar {
private $user;
/** @var ILogger */
private $logger;
+ /** @var IConfig */
+ private $config;
/**
* constructor
@@ -60,12 +63,18 @@ class Avatar implements IAvatar {
* @param IL10N $l
* @param User $user
* @param ILogger $logger
+ * @param IConfig $config
*/
- public function __construct (Folder $folder, IL10N $l, $user, ILogger $logger) {
+ public function __construct(Folder $folder,
+ IL10N $l,
+ $user,
+ ILogger $logger,
+ IConfig $config) {
$this->folder = $folder;
$this->l = $l;
$this->user = $user;
$this->logger = $logger;
+ $this->config = $config;
}
/**
@@ -137,6 +146,9 @@ class Avatar implements IAvatar {
$regex = '/^avatar\.([0-9]+\.)?(jpg|png)$/';
$avatars = $this->folder->getDirectoryListing();
+ $this->config->setUserValue($this->user->getUID(), 'avatar', 'version',
+ (int)$this->config->getUserValue($this->user->getUID(), 'avatar', 'version', 0) + 1);
+
foreach ($avatars as $avatar) {
if (preg_match($regex, $avatar->getName())) {
$avatar->delete();
diff --git a/lib/private/AvatarManager.php b/lib/private/AvatarManager.php
index e461a70608b..0eabc3a1754 100644
--- a/lib/private/AvatarManager.php
+++ b/lib/private/AvatarManager.php
@@ -30,6 +30,7 @@ namespace OC;
use OCP\Files\Folder;
use OCP\Files\NotFoundException;
use OCP\IAvatarManager;
+use OCP\IConfig;
use OCP\ILogger;
use OCP\IUserManager;
use OCP\Files\IRootFolder;
@@ -52,6 +53,9 @@ class AvatarManager implements IAvatarManager {
/** @var ILogger */
private $logger;
+ /** @var IConfig */
+ private $config;
+
/**
* AvatarManager constructor.
*
@@ -59,16 +63,19 @@ class AvatarManager implements IAvatarManager {
* @param IRootFolder $rootFolder
* @param IL10N $l
* @param ILogger $logger
+ * @param IConfig $config
*/
public function __construct(
IUserManager $userManager,
IRootFolder $rootFolder,
IL10N $l,
- ILogger $logger) {
+ ILogger $logger,
+ IConfig $config) {
$this->userManager = $userManager;
$this->rootFolder = $rootFolder;
$this->l = $l;
$this->logger = $logger;
+ $this->config = $config;
}
/**
@@ -94,6 +101,6 @@ class AvatarManager implements IAvatarManager {
/** @var Folder $folder */
$folder = $this->rootFolder->get($dir);
- return new Avatar($folder, $this->l, $user, $this->logger);
+ return new Avatar($folder, $this->l, $user, $this->logger, $this->config);
}
}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 6f6d403210d..494387ab6ca 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -361,7 +361,8 @@ class Server extends ServerContainer implements IServerContainer {
$c->getUserManager(),
$c->getRootFolder(),
$c->getL10N('lib'),
- $c->getLogger()
+ $c->getLogger(),
+ $c->getConfig()
);
});
$this->registerService('Logger', function (Server $c) {
diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php
index 7e5c120717f..da845d80d04 100644
--- a/lib/private/TemplateLayout.php
+++ b/lib/private/TemplateLayout.php
@@ -112,6 +112,7 @@ class TemplateLayout extends \OC_Template {
$this->assign('userAvatarSet', false);
} else {
$this->assign('userAvatarSet', \OC::$server->getAvatarManager()->getAvatar(\OC_User::getUser())->exists());
+ $this->assign('userAvatarVersion', \OC::$server->getConfig()->getUserValue(\OC_User::getUser(), 'avatar', 'version', 0));
}
} else if ($renderAs == 'error') {