summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2022-08-02 16:19:05 +0200
committerRobin Appelman <robin@icewind.nl>2022-08-02 16:19:05 +0200
commit77ec419ef42cd4a47defe9e03bdc6c65d47eb6d9 (patch)
tree2933a1251f9f02bf16d11e194ef40685fb8f1121
parent6b83d761f6c4d6db0103f8fd669f3343890b4a96 (diff)
use unique filenames in albums
-rw-r--r--appinfo/info.xml3
-rw-r--r--lib/Album/AlbumWithFiles.php2
-rw-r--r--lib/Sabre/Album/AlbumPhoto.php6
-rw-r--r--lib/Sabre/Album/AlbumRoot.php2
-rw-r--r--lib/Sabre/Album/PropFindPlugin.php50
5 files changed, 59 insertions, 4 deletions
diff --git a/appinfo/info.xml b/appinfo/info.xml
index 0b744b35..e8b4dab6 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -33,5 +33,8 @@
<collections>
<collection>OCA\Photos\Sabre\RootCollection</collection>
</collections>
+ <plugins>
+ <plugin>OCA\Photos\Sabre\Album\PropFindPlugin</plugin>
+ </plugins>
</sabre>
</info>
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 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+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();
+ });
+ }
+}