Fix inspection results
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
836271e0fd
commit
f0850b266e
|
@ -28,7 +28,7 @@ use Sabre\DAV\Exception\Forbidden;
|
||||||
use Sabre\DAV\Exception\MethodNotAllowed;
|
use Sabre\DAV\Exception\MethodNotAllowed;
|
||||||
use Sabre\DAV\Exception\NotFound;
|
use Sabre\DAV\Exception\NotFound;
|
||||||
use Sabre\DAV\ICollection;
|
use Sabre\DAV\ICollection;
|
||||||
use Sabre\HTTP\URLUtil;
|
use Sabre\Uri;
|
||||||
|
|
||||||
class AvatarHome implements ICollection {
|
class AvatarHome implements ICollection {
|
||||||
|
|
||||||
|
@ -41,25 +41,26 @@ class AvatarHome implements ICollection {
|
||||||
* AvatarHome constructor.
|
* AvatarHome constructor.
|
||||||
*
|
*
|
||||||
* @param array $principalInfo
|
* @param array $principalInfo
|
||||||
|
* @param IAvatarManager $avatarManager
|
||||||
*/
|
*/
|
||||||
public function __construct($principalInfo, IAvatarManager $avatarManager) {
|
public function __construct($principalInfo, IAvatarManager $avatarManager) {
|
||||||
$this->principalInfo = $principalInfo;
|
$this->principalInfo = $principalInfo;
|
||||||
$this->avatarManager = $avatarManager;
|
$this->avatarManager = $avatarManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createFile($name, $data = null) {
|
public function createFile($name, $data = null) {
|
||||||
throw new Forbidden('Permission denied to create a file');
|
throw new Forbidden('Permission denied to create a file');
|
||||||
}
|
}
|
||||||
|
|
||||||
function createDirectory($name) {
|
public function createDirectory($name) {
|
||||||
throw new Forbidden('Permission denied to create a folder');
|
throw new Forbidden('Permission denied to create a folder');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getChild($name) {
|
public function getChild($name) {
|
||||||
$elements = pathinfo($name);
|
$elements = pathinfo($name);
|
||||||
$ext = isset($elements['extension']) ? $elements['extension'] : '';
|
$ext = isset($elements['extension']) ? $elements['extension'] : '';
|
||||||
$size = intval(isset($elements['filename']) ? $elements['filename'] : '64');
|
$size = (int)(isset($elements['filename']) ? $elements['filename'] : '64');
|
||||||
if (!in_array($ext, ['jpeg', 'png'])) {
|
if (!in_array($ext, ['jpeg', 'png'], true)) {
|
||||||
throw new MethodNotAllowed('File format not allowed');
|
throw new MethodNotAllowed('File format not allowed');
|
||||||
}
|
}
|
||||||
if ($size <= 0 || $size > 1024) {
|
if ($size <= 0 || $size > 1024) {
|
||||||
|
@ -72,7 +73,7 @@ class AvatarHome implements ICollection {
|
||||||
return new AvatarNode($size, $ext, $avatar);
|
return new AvatarNode($size, $ext, $avatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getChildren() {
|
public function getChildren() {
|
||||||
try {
|
try {
|
||||||
return [
|
return [
|
||||||
$this->getChild('96.jpeg')
|
$this->getChild('96.jpeg')
|
||||||
|
@ -82,10 +83,10 @@ class AvatarHome implements ICollection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function childExists($name) {
|
public function childExists($name) {
|
||||||
try {
|
try {
|
||||||
$ret = $this->getChild($name);
|
$ret = $this->getChild($name);
|
||||||
return !is_null($ret);
|
return $ret !== null;
|
||||||
} catch (NotFound $ex) {
|
} catch (NotFound $ex) {
|
||||||
return false;
|
return false;
|
||||||
} catch (MethodNotAllowed $ex) {
|
} catch (MethodNotAllowed $ex) {
|
||||||
|
@ -93,16 +94,16 @@ class AvatarHome implements ICollection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete() {
|
public function delete() {
|
||||||
throw new Forbidden('Permission denied to delete this folder');
|
throw new Forbidden('Permission denied to delete this folder');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getName() {
|
public function getName() {
|
||||||
list(,$name) = URLUtil::splitPath($this->principalInfo['uri']);
|
list(,$name) = Uri\split($this->principalInfo['uri']);
|
||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setName($name) {
|
public function setName($name) {
|
||||||
throw new Forbidden('Permission denied to rename this folder');
|
throw new Forbidden('Permission denied to rename this folder');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +112,7 @@ class AvatarHome implements ICollection {
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
function getLastModified() {
|
public function getLastModified() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,11 +51,11 @@ class AvatarNode extends File {
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function getName() {
|
public function getName() {
|
||||||
return "$this->size.$this->ext";
|
return "$this->size.$this->ext";
|
||||||
}
|
}
|
||||||
|
|
||||||
function get() {
|
public function get() {
|
||||||
$image = $this->avatar->get($this->size);
|
$image = $this->avatar->get($this->size);
|
||||||
$res = $image->resource();
|
$res = $image->resource();
|
||||||
|
|
||||||
|
@ -75,18 +75,18 @@ class AvatarNode extends File {
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
function getContentType() {
|
public function getContentType() {
|
||||||
if ($this->ext === 'png') {
|
if ($this->ext === 'png') {
|
||||||
return 'image/png';
|
return 'image/png';
|
||||||
}
|
}
|
||||||
return 'image/jpeg';
|
return 'image/jpeg';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getETag() {
|
public function getETag() {
|
||||||
return $this->avatar->getFile($this->size)->getEtag();
|
return $this->avatar->getFile($this->size)->getEtag();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLastModified() {
|
public function getLastModified() {
|
||||||
$timestamp = $this->avatar->getFile($this->size)->getMTime();
|
$timestamp = $this->avatar->getFile($this->size)->getMTime();
|
||||||
if (!empty($timestamp)) {
|
if (!empty($timestamp)) {
|
||||||
return (int)$timestamp;
|
return (int)$timestamp;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
namespace OCA\DAV\Avatars;
|
namespace OCA\DAV\Avatars;
|
||||||
|
|
||||||
use Sabre\DAVACL\AbstractPrincipalCollection;
|
use Sabre\DAVACL\AbstractPrincipalCollection;
|
||||||
use Sabre\DAVACL\IPrincipal;
|
|
||||||
|
|
||||||
class RootCollection extends AbstractPrincipalCollection {
|
class RootCollection extends AbstractPrincipalCollection {
|
||||||
|
|
||||||
|
@ -17,12 +17,12 @@ class RootCollection extends AbstractPrincipalCollection {
|
||||||
* @param array $principalInfo
|
* @param array $principalInfo
|
||||||
* @return AvatarHome
|
* @return AvatarHome
|
||||||
*/
|
*/
|
||||||
function getChildForPrincipal(array $principalInfo) {
|
public function getChildForPrincipal(array $principalInfo) {
|
||||||
$avatarManager = \OC::$server->getAvatarManager();
|
$avatarManager = \OC::$server->getAvatarManager();
|
||||||
return new AvatarHome($principalInfo, $avatarManager);
|
return new AvatarHome($principalInfo, $avatarManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getName() {
|
public function getName() {
|
||||||
return 'avatars';
|
return 'avatars';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue