2016-12-23 14:12:38 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2017-11-06 17:56:42 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud GmbH
|
|
|
|
*
|
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-12-23 14:12:38 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2016-12-23 14:12:38 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\DAV\Avatars;
|
|
|
|
|
2017-03-22 01:10:39 +03:00
|
|
|
use OCP\IAvatarManager;
|
2016-12-23 14:12:38 +03:00
|
|
|
use Sabre\DAV\Exception\Forbidden;
|
|
|
|
use Sabre\DAV\Exception\MethodNotAllowed;
|
|
|
|
use Sabre\DAV\Exception\NotFound;
|
|
|
|
use Sabre\DAV\ICollection;
|
2017-03-26 12:32:29 +03:00
|
|
|
use Sabre\Uri;
|
2016-12-23 14:12:38 +03:00
|
|
|
|
|
|
|
class AvatarHome implements ICollection {
|
2017-03-22 01:10:39 +03:00
|
|
|
|
|
|
|
/** @var array */
|
2016-12-23 14:12:38 +03:00
|
|
|
private $principalInfo;
|
2017-03-22 01:10:39 +03:00
|
|
|
/** @var IAvatarManager */
|
|
|
|
private $avatarManager;
|
2016-12-23 14:12:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* AvatarHome constructor.
|
|
|
|
*
|
|
|
|
* @param array $principalInfo
|
2017-03-26 12:32:29 +03:00
|
|
|
* @param IAvatarManager $avatarManager
|
2016-12-23 14:12:38 +03:00
|
|
|
*/
|
2017-03-22 01:10:39 +03:00
|
|
|
public function __construct($principalInfo, IAvatarManager $avatarManager) {
|
2016-12-23 14:12:38 +03:00
|
|
|
$this->principalInfo = $principalInfo;
|
2017-03-22 01:10:39 +03:00
|
|
|
$this->avatarManager = $avatarManager;
|
2016-12-23 14:12:38 +03:00
|
|
|
}
|
|
|
|
|
2017-03-26 12:32:29 +03:00
|
|
|
public function createFile($name, $data = null) {
|
2016-12-23 14:12:38 +03:00
|
|
|
throw new Forbidden('Permission denied to create a file');
|
|
|
|
}
|
|
|
|
|
2017-03-26 12:32:29 +03:00
|
|
|
public function createDirectory($name) {
|
2016-12-23 14:12:38 +03:00
|
|
|
throw new Forbidden('Permission denied to create a folder');
|
|
|
|
}
|
|
|
|
|
2017-03-26 12:32:29 +03:00
|
|
|
public function getChild($name) {
|
2016-12-23 14:12:38 +03:00
|
|
|
$elements = pathinfo($name);
|
|
|
|
$ext = isset($elements['extension']) ? $elements['extension'] : '';
|
2017-03-26 12:32:29 +03:00
|
|
|
$size = (int)(isset($elements['filename']) ? $elements['filename'] : '64');
|
|
|
|
if (!in_array($ext, ['jpeg', 'png'], true)) {
|
2016-12-23 14:12:38 +03:00
|
|
|
throw new MethodNotAllowed('File format not allowed');
|
|
|
|
}
|
|
|
|
if ($size <= 0 || $size > 1024) {
|
|
|
|
throw new MethodNotAllowed('Invalid image size');
|
|
|
|
}
|
2017-03-22 01:10:39 +03:00
|
|
|
$avatar = $this->avatarManager->getAvatar($this->getName());
|
2018-01-16 17:37:47 +03:00
|
|
|
if (!$avatar->exists()) {
|
2016-12-23 14:12:38 +03:00
|
|
|
throw new NotFound();
|
|
|
|
}
|
|
|
|
return new AvatarNode($size, $ext, $avatar);
|
|
|
|
}
|
|
|
|
|
2017-03-26 12:32:29 +03:00
|
|
|
public function getChildren() {
|
2016-12-23 14:12:38 +03:00
|
|
|
try {
|
|
|
|
return [
|
|
|
|
$this->getChild('96.jpeg')
|
|
|
|
];
|
|
|
|
} catch(NotFound $exception) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-26 12:32:29 +03:00
|
|
|
public function childExists($name) {
|
2017-03-22 01:10:39 +03:00
|
|
|
try {
|
|
|
|
$ret = $this->getChild($name);
|
2017-03-26 12:32:29 +03:00
|
|
|
return $ret !== null;
|
2017-03-22 01:10:39 +03:00
|
|
|
} catch (NotFound $ex) {
|
|
|
|
return false;
|
|
|
|
} catch (MethodNotAllowed $ex) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-12-23 14:12:38 +03:00
|
|
|
}
|
|
|
|
|
2017-03-26 12:32:29 +03:00
|
|
|
public function delete() {
|
2016-12-23 14:12:38 +03:00
|
|
|
throw new Forbidden('Permission denied to delete this folder');
|
|
|
|
}
|
|
|
|
|
2017-03-26 12:32:29 +03:00
|
|
|
public function getName() {
|
|
|
|
list(,$name) = Uri\split($this->principalInfo['uri']);
|
2016-12-23 14:12:38 +03:00
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
|
2017-03-26 12:32:29 +03:00
|
|
|
public function setName($name) {
|
2016-12-23 14:12:38 +03:00
|
|
|
throw new Forbidden('Permission denied to rename this folder');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the last modification time, as a unix timestamp
|
|
|
|
*
|
2017-03-26 12:34:21 +03:00
|
|
|
* @return int|null
|
2016-12-23 14:12:38 +03:00
|
|
|
*/
|
2017-03-26 12:32:29 +03:00
|
|
|
public function getLastModified() {
|
2016-12-23 14:12:38 +03:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|