summaryrefslogtreecommitdiffstats
path: root/lib/private/Avatar.php
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/Avatar.php
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/Avatar.php')
-rw-r--r--lib/private/Avatar.php14
1 files changed, 13 insertions, 1 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();