-
-
Notifications
You must be signed in to change notification settings - Fork 62
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 DAV endpoint for location grouping #1335
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,90 +26,36 @@ | |
use OCA\Photos\Album\AlbumFile; | ||
use OCA\Photos\Album\AlbumInfo; | ||
use OCA\Photos\Album\AlbumMapper; | ||
use OCA\Photos\Sabre\CollectionPhoto; | ||
use OCP\Files\IRootFolder; | ||
use OCP\Files\Node; | ||
use OCP\Files\File; | ||
use OCP\Files\Folder; | ||
use OCP\Files\NotFoundException; | ||
use Sabre\DAV\Exception\Forbidden; | ||
use Sabre\DAV\IFile; | ||
|
||
class AlbumPhoto implements IFile { | ||
private AlbumMapper $albumMapper; | ||
private AlbumInfo $album; | ||
private AlbumFile $albumFile; | ||
private IRootFolder $rootFolder; | ||
|
||
public const TAG_FAVORITE = '_$!<Favorite>!$_'; | ||
|
||
public function __construct(AlbumMapper $albumMapper, AlbumInfo $album, AlbumFile $albumFile, IRootFolder $rootFolder) { | ||
$this->albumMapper = $albumMapper; | ||
$this->album = $album; | ||
$this->albumFile = $albumFile; | ||
$this->rootFolder = $rootFolder; | ||
class AlbumPhoto extends CollectionPhoto implements IFile { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review hint: some bits extracted to |
||
public function __construct( | ||
private AlbumMapper $albumMapper, | ||
private AlbumInfo $album, | ||
private AlbumFile $albumFile, | ||
private IRootFolder $rootFolder, | ||
Folder $userFolder, | ||
) { | ||
parent::__construct($albumFile, $userFolder); | ||
artonge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function delete() { | ||
$this->albumMapper->removeFile($this->album->getId(), $this->albumFile->getFileId()); | ||
} | ||
|
||
public function getName() { | ||
return $this->albumFile->getFileId() . "-" . $this->albumFile->getName(); | ||
} | ||
|
||
/** | ||
* @return never | ||
*/ | ||
public function setName($name) { | ||
throw new Forbidden('Can\'t rename photos trough the album api'); | ||
} | ||
|
||
public function getLastModified() { | ||
return $this->albumFile->getMTime(); | ||
} | ||
|
||
public function put($data) { | ||
$nodes = $this->userFolder->getById($this->file->getFileId()); | ||
$node = current($nodes); | ||
if ($node) { | ||
/** @var Node $node */ | ||
if ($node instanceof File) { | ||
return $node->putContent($data); | ||
} else { | ||
throw new NotFoundException("Photo is a folder"); | ||
} | ||
} else { | ||
throw new NotFoundException("Photo not found for user"); | ||
} | ||
} | ||
|
||
public function get() { | ||
$nodes = $this->rootFolder | ||
->getUserFolder($this->albumFile->getOwner() ?: $this->album->getUserId()) | ||
->getById($this->albumFile->getFileId()); | ||
$node = current($nodes); | ||
if ($node) { | ||
/** @var Node $node */ | ||
if ($node instanceof File) { | ||
return $node->fopen('r'); | ||
} else { | ||
throw new NotFoundException("Photo is a folder"); | ||
} | ||
} else { | ||
throw new NotFoundException("Photo not found for user"); | ||
} | ||
} | ||
|
||
public function getFileId(): int { | ||
return $this->albumFile->getFileId(); | ||
$this->albumMapper->removeFile($this->album->getId(), $this->file->getFileId()); | ||
} | ||
|
||
public function getFileInfo(): Node { | ||
private function getNode(): Node { | ||
$nodes = $this->rootFolder | ||
->getUserFolder($this->albumFile->getOwner() ?: $this->album->getUserId()) | ||
->getById($this->albumFile->getFileId()); | ||
->getById($this->file->getFileId()); | ||
$node = current($nodes); | ||
if ($node) { | ||
return $node; | ||
|
@@ -118,48 +64,16 @@ public function getFileInfo(): Node { | |
} | ||
} | ||
|
||
public function getContentType() { | ||
return $this->albumFile->getMimeType(); | ||
} | ||
|
||
public function getETag() { | ||
return $this->albumFile->getEtag(); | ||
} | ||
|
||
public function getSize() { | ||
return $this->albumFile->getSize(); | ||
} | ||
|
||
public function getFile(): AlbumFile { | ||
return $this->albumFile; | ||
} | ||
|
||
public function isFavorite(): bool { | ||
$tagManager = \OCP\Server::get(\OCP\ITagManager::class); | ||
$tagger = $tagManager->load('files'); | ||
if ($tagger === null) { | ||
return false; | ||
} | ||
$tags = $tagger->getTagsForObjects([$this->getFileId()]); | ||
|
||
if ($tags === false || empty($tags)) { | ||
return false; | ||
public function get() { | ||
$node = $this->getNode(); | ||
if ($node instanceof File) { | ||
return $node->fopen('r'); | ||
} else { | ||
throw new NotFoundException("Photo is a folder"); | ||
} | ||
|
||
return array_search(self::TAG_FAVORITE, current($tags)) !== false; | ||
} | ||
|
||
public function setFavoriteState($favoriteState): bool { | ||
$tagManager = \OCP\Server::get(\OCP\ITagManager::class); | ||
$tagger = $tagManager->load('files'); | ||
|
||
switch ($favoriteState) { | ||
case "0": | ||
return $tagger->removeFromFavorites($this->albumFile->getFileId()); | ||
case "1": | ||
return $tagger->addToFavorites($this->albumFile->getFileId()); | ||
default: | ||
new \Exception('Favorite state is invalide, should be 0 or 1.'); | ||
} | ||
public function getFileInfo(): Node { | ||
return $this->getNode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review hint: moved as it is not restricted to albums.