Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/photos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2022-09-28 12:01:12 +0300
committerLouis Chemineau <louis@chmn.me>2022-10-20 12:59:48 +0300
commit01f33ad7b5a3235369a39744c6a33c06dec40f0f (patch)
tree46d5e8d98bd8b01b03f17d02aa488a8f37c7f977
parent47697b4ba14f9f1d9e87a97414687a15482692b2 (diff)
Refactor getting album storage folder
Signed-off-by: Louis Chemineau <louis@chmn.me>
-rw-r--r--lib/Sabre/Album/AlbumRoot.php12
-rw-r--r--lib/Sabre/Album/PublicAlbumRoot.php37
-rw-r--r--lib/Service/UserConfigService.php1
3 files changed, 15 insertions, 35 deletions
diff --git a/lib/Sabre/Album/AlbumRoot.php b/lib/Sabre/Album/AlbumRoot.php
index f0445d85..0406a8c3 100644
--- a/lib/Sabre/Album/AlbumRoot.php
+++ b/lib/Sabre/Album/AlbumRoot.php
@@ -80,6 +80,12 @@ class AlbumRoot implements ICollection, ICopyTarget {
$this->albumMapper->rename($this->album->getAlbum()->getId(), $name);
}
+ protected function getPhotosLocationInfo() {
+ $photosLocation = $this->userConfigService->getUserConfig('photosLocation');
+ $userFolder = $this->rootFolder->getUserFolder($this->user->getUID());
+ return [$photosLocation, $userFolder];
+ }
+
/**
* We cannot create files in an Album
* We add the file to the default Photos folder and then link it there.
@@ -90,13 +96,13 @@ class AlbumRoot implements ICollection, ICopyTarget {
*/
public function createFile($name, $data = null) {
try {
- $photosLocation = $this->userConfigService->getUserConfig('photosLocation');
+ [$photosLocation, $userFolder] = $this->getPhotosLocationInfo();
try {
- $photosFolder = $this->userFolder->get($photosLocation);
+ $photosFolder = $userFolder->get($photosLocation);
} catch (NotFoundException $e) {
// If the folder does not exists, create it
- $photosFolder = $this->userFolder->newFolder($photosLocation);
+ $photosFolder = $userFolder->newFolder($photosLocation);
}
// If the node is not a folder, we throw
diff --git a/lib/Sabre/Album/PublicAlbumRoot.php b/lib/Sabre/Album/PublicAlbumRoot.php
index 19cff6bb..ab4e6fc4 100644
--- a/lib/Sabre/Album/PublicAlbumRoot.php
+++ b/lib/Sabre/Album/PublicAlbumRoot.php
@@ -47,38 +47,11 @@ class PublicAlbumRoot extends AlbumRoot {
throw new Forbidden('Not allowed to copy into a public album');
}
- /**
- * We cannot create files in an Album
- * We add the file to the default Photos folder and then link it there.
- *
- * @param string $name
- * @param null|resource|string $data
- * @return null
- */
- public function createFile($name, $data = null) {
- // TODO: implement public album upload
- throw new Forbidden('Not allowed to create a file in a public album');
-
- try {
- $albumOwner = $this->album->getAlbum()->getUserId();
- $photosLocation = $this->userConfigService->getConfigForUser($albumOwner, 'photosLocation');
- $photosFolder = $this->rootFolder->getUserFolder($albumOwner)->get($photosLocation);
- if (!($photosFolder instanceof Folder)) {
- throw new Conflict('The destination exists and is not a folder');
- }
-
- // Check for conflict and rename the file accordingly
- $newName = \basename(\OC_Helper::buildNotExistingFileName($photosLocation, $name));
-
- $node = $photosFolder->newFile($newName, $data);
- $this->addFile($node->getId(), $node->getOwner()->getUID());
- // Cheating with header because we are using fileID-fileName
- // https://github.com/nextcloud/server/blob/af29b978078ffd9169a9bd9146feccbb7974c900/apps/dav/lib/Connector/Sabre/FilesPlugin.php#L564-L585
- \header('OC-FileId: ' . $node->getId());
- return '"' . $node->getEtag() . '"';
- } catch (\Exception $e) {
- throw new Forbidden('Could not create file');
- }
+ protected function getPhotosLocationInfo() {
+ $albumOwner = $this->album->getAlbum()->getUserId();
+ $photosLocation = $this->userConfigService->getConfigForUser($albumOwner, 'photosLocation');
+ $userFolder = $this->rootFolder->getUserFolder($albumOwner);
+ return [$photosLocation, $userFolder];
}
protected function addFile(int $sourceId, string $ownerUID): bool {
diff --git a/lib/Service/UserConfigService.php b/lib/Service/UserConfigService.php
index 0a3ced64..fa7aba23 100644
--- a/lib/Service/UserConfigService.php
+++ b/lib/Service/UserConfigService.php
@@ -56,6 +56,7 @@ class UserConfigService {
if (!in_array($key, array_keys(self::DEFAULT_CONFIGS))) {
throw new Exception('Unknown user config key');
}
+
$default = self::DEFAULT_CONFIGS[$key];
$value = $this->config->getUserValue($userId, Application::APP_ID, $key, $default);