Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Albums view #1142

Merged
merged 12 commits into from
Aug 23, 2022
Prev Previous commit
Next Next commit
use unique filenames in albums
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
icewind1991 authored and artonge committed Aug 22, 2022
commit 62dbf99ec049a24061fe9238461eccd2cf67d609
3 changes: 3 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@
<collections>
<collection>OCA\Photos\Sabre\RootCollection</collection>
</collections>
<plugins>
<plugin>OCA\Photos\Sabre\Album\PropFindPlugin</plugin>
</plugins>
</sabre>
</info>
2 changes: 0 additions & 2 deletions lib/Album/AlbumWithFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

namespace OCA\Photos\Album;

use OC\Files\Cache\CacheEntry;

class AlbumWithFiles {
private AlbumInfo $info;
/** @var AlbumFile[] */
Expand Down
6 changes: 5 additions & 1 deletion lib/Sabre/Album/AlbumPhoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function delete() {
}

public function getName() {
return $this->file->getName();
return $this->file->getFileId() . "-" . $this->file->getName();
}

public function setName($name) {
Expand Down Expand Up @@ -92,4 +92,8 @@ public function getETag() {
public function getSize() {
return $this->file->getSize();
}

public function getFile(): AlbumFile {
return $this->file;
}
}
2 changes: 1 addition & 1 deletion lib/Sabre/Album/AlbumRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getChildren(): array {

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);
}
}
Expand Down
50 changes: 50 additions & 0 deletions lib/Sabre/Album/PropFindPlugin.php
Original file line number Diff line number Diff line change
@@ -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();
});
}
}