From 62dbf99ec049a24061fe9238461eccd2cf67d609 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 2 Aug 2022 16:19:05 +0200 Subject: use unique filenames in albums Signed-off-by: Louis Chemineau --- lib/Album/AlbumWithFiles.php | 2 -- lib/Sabre/Album/AlbumPhoto.php | 6 ++++- lib/Sabre/Album/AlbumRoot.php | 2 +- lib/Sabre/Album/PropFindPlugin.php | 50 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 lib/Sabre/Album/PropFindPlugin.php (limited to 'lib') diff --git a/lib/Album/AlbumWithFiles.php b/lib/Album/AlbumWithFiles.php index d4724091..cc6d0d1a 100644 --- a/lib/Album/AlbumWithFiles.php +++ b/lib/Album/AlbumWithFiles.php @@ -23,8 +23,6 @@ declare(strict_types=1); namespace OCA\Photos\Album; -use OC\Files\Cache\CacheEntry; - class AlbumWithFiles { private AlbumInfo $info; /** @var AlbumFile[] */ diff --git a/lib/Sabre/Album/AlbumPhoto.php b/lib/Sabre/Album/AlbumPhoto.php index 88985139..5bd31830 100644 --- a/lib/Sabre/Album/AlbumPhoto.php +++ b/lib/Sabre/Album/AlbumPhoto.php @@ -51,7 +51,7 @@ class AlbumPhoto implements IFile { } public function getName() { - return $this->file->getName(); + return $this->file->getFileId() . "-" . $this->file->getName(); } public function setName($name) { @@ -92,4 +92,8 @@ class AlbumPhoto implements IFile { public function getSize() { return $this->file->getSize(); } + + public function getFile(): AlbumFile { + return $this->file; + } } diff --git a/lib/Sabre/Album/AlbumRoot.php b/lib/Sabre/Album/AlbumRoot.php index 222fa53c..4a51d619 100644 --- a/lib/Sabre/Album/AlbumRoot.php +++ b/lib/Sabre/Album/AlbumRoot.php @@ -80,7 +80,7 @@ class AlbumRoot implements ICollection, ICopyTarget { public function getChild($name): AlbumPhoto { foreach ($this->album->getFiles() as $file) { - if ($file->getName() === $name) { + if ($file->getFileId() . "-" . $file->getName() === $name) { return new AlbumPhoto($this->albumMapper, $this->album->getAlbum(), $file, $this->userFolder); } } diff --git a/lib/Sabre/Album/PropFindPlugin.php b/lib/Sabre/Album/PropFindPlugin.php new file mode 100644 index 00000000..02b62096 --- /dev/null +++ b/lib/Sabre/Album/PropFindPlugin.php @@ -0,0 +1,50 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see . + * + */ + +namespace OCA\Photos\Sabre\Album; + +use Sabre\DAV\INode; +use Sabre\DAV\PropFind; +use Sabre\DAV\Server; +use Sabre\DAV\ServerPlugin; + +class PropFindPlugin extends ServerPlugin { + private Server $server; + + public function initialize(Server $server) { + $this->server = $server; + + $this->server->on('propFind', [$this, 'propFind']); + } + + + public function propFind(PropFind $propFind, INode $node) { + if (!($node instanceof AlbumPhoto)) { + return; + } + + $propFind->handle('{http://nextcloud.org/ns}file-name', function () use ($node) { + return $node->getFile()->getName(); + }); + } +} -- cgit v1.2.3