migrate therinaldos.com data
Build & Deploy to DigitalOcean Space / build (push) Failing after 2m38s

This commit is contained in:
2024-05-05 15:50:45 -04:00
commit ef1ff240d4
23182 changed files with 3801898 additions and 0 deletions
@@ -0,0 +1,79 @@
<?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 OCA\Photos\Album\AlbumFile;
use OCA\Photos\Album\AlbumInfo;
use OCA\Photos\Album\AlbumMapper;
use OCA\Photos\Sabre\CollectionPhoto;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use Sabre\DAV\IFile;
class AlbumPhoto extends CollectionPhoto implements IFile {
public function __construct(
private AlbumMapper $albumMapper,
private AlbumInfo $album,
private AlbumFile $albumFile,
private IRootFolder $rootFolder,
Folder $userFolder,
) {
parent::__construct($albumFile, $userFolder);
}
/**
* @return void
*/
public function delete() {
$this->albumMapper->removeFile($this->album->getId(), $this->file->getFileId());
}
private function getNode(): Node {
$nodes = $this->rootFolder
->getUserFolder($this->albumFile->getOwner() ?: $this->album->getUserId())
->getById($this->file->getFileId());
$node = current($nodes);
if ($node) {
return $node;
} else {
throw new NotFoundException("Photo not found for user");
}
}
public function get() {
$node = $this->getNode();
if ($node instanceof File) {
return $node->fopen('r');
} else {
throw new NotFoundException("Photo is a folder");
}
}
public function getFileInfo(): Node {
return $this->getNode();
}
}
@@ -0,0 +1,244 @@
<?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 OCA\DAV\Connector\Sabre\File;
use OCA\Photos\Album\AlbumFile;
use OCA\Photos\Album\AlbumMapper;
use OCA\Photos\Album\AlbumWithFiles;
use OCA\Photos\Service\UserConfigService;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use Sabre\DAV\Exception\Conflict;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
use Sabre\DAV\ICopyTarget;
use Sabre\DAV\INode;
class AlbumRoot implements ICollection, ICopyTarget {
protected AlbumMapper $albumMapper;
protected AlbumWithFiles $album;
protected IRootFolder $rootFolder;
protected string $userId;
public function __construct(
AlbumMapper $albumMapper,
AlbumWithFiles $album,
IRootFolder $rootFolder,
string $userId,
UserConfigService $userConfigService
) {
$this->albumMapper = $albumMapper;
$this->album = $album;
$this->rootFolder = $rootFolder;
$this->userId = $userId;
$this->userConfigService = $userConfigService;
}
/**
* @return void
*/
public function delete() {
$this->albumMapper->delete($this->album->getAlbum()->getId());
}
public function getName(): string {
return basename($this->album->getAlbum()->getTitle());
}
/**
* @return void
*/
public function setName($name) {
$this->albumMapper->rename($this->album->getAlbum()->getId(), $name);
}
protected function getPhotosLocationInfo() {
$photosLocation = $this->userConfigService->getUserConfig('photosLocation');
$userFolder = $this->rootFolder->getUserFolder($this->userId);
return [$photosLocation, $userFolder];
}
/**
* 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 void
*/
public function createFile($name, $data = null) {
try {
[$photosLocation, $userFolder] = $this->getPhotosLocationInfo();
try {
$photosFolder = $userFolder->get($photosLocation);
} catch (NotFoundException $e) {
// If the folder does not exists, create it
$photosFolder = $userFolder->newFolder($photosLocation);
}
// If the node is not a folder, we throw
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');
}
}
/**
* @return never
*/
public function createDirectory($name) {
throw new Forbidden('Not allowed to create directories in this folder');
}
public function getChildren(): array {
return array_map(function (AlbumFile $file) {
return new AlbumPhoto($this->albumMapper, $this->album->getAlbum(), $file, $this->rootFolder, $this->rootFolder->getUserFolder($this->userId));
}, $this->album->getFiles());
}
public function getChild($name): AlbumPhoto {
foreach ($this->album->getFiles() as $file) {
if ($file->getFileId() . "-" . $file->getName() === $name) {
return new AlbumPhoto($this->albumMapper, $this->album->getAlbum(), $file, $this->rootFolder, $this->rootFolder->getUserFolder($this->userId));
}
}
throw new NotFound("$name not found");
}
public function childExists($name): bool {
try {
$this->getChild($name);
return true;
} catch (NotFound $e) {
return false;
}
}
public function getLastModified(): int {
return 0;
}
public function copyInto($targetName, $sourcePath, INode $sourceNode): bool {
if (!$sourceNode instanceof File) {
throw new Forbidden("The source is not a file");
}
$sourceId = $sourceNode->getId();
$ownerUID = $sourceNode->getFileInfo()->getOwner()->getUID();
$uid = $this->userId;
if ($ownerUID !== $uid) {
throw new Forbidden("Can't add file to album, only files from $uid can be added");
}
return $this->addFile($sourceId, $ownerUID);
}
protected function addFile(int $sourceId, string $ownerUID): bool {
if (in_array($sourceId, $this->album->getFileIds())) {
throw new Conflict("File $sourceId is already in the folder");
}
if ($ownerUID === $this->userId) {
$this->albumMapper->addFile($this->album->getAlbum()->getId(), $sourceId, $ownerUID);
$node = current($this->rootFolder->getUserFolder($ownerUID)->getById($sourceId));
$this->album->addFile(new AlbumFile($sourceId, $node->getName(), $node->getMimetype(), $node->getSize(), $node->getMTime(), $node->getEtag(), $node->getCreationTime(), $ownerUID));
return true;
}
return false;
}
public function getAlbum(): AlbumWithFiles {
return $this->album;
}
public function getDateRange(): array {
$earliestDate = null;
$latestDate = null;
foreach ($this->getChildren() as $child) {
try {
$childCreationDate = $child->getFileInfo()->getMtime();
} catch (NotFoundException $e) {
continue;
}
if ($childCreationDate < $earliestDate || $earliestDate === null) {
$earliestDate = $childCreationDate;
}
if ($childCreationDate > $earliestDate || $latestDate === null) {
$latestDate = $childCreationDate;
}
}
return ['start' => $earliestDate, 'end' => $latestDate];
}
/**
* @return int|null
*/
public function getCover() {
$children = $this->getChildren();
if (count($children) > 0) {
return $children[0]->getFileId();
} else {
return null;
}
}
/**
* @return array{array{'nc:collaborator': array{'id': string, 'label': string, 'type': int}}}
*/
public function getCollaborators(): array {
return array_map(
fn (array $collaborator) => [ 'nc:collaborator' => $collaborator ],
$this->albumMapper->getCollaborators($this->album->getAlbum()->getId()),
);
}
/**
* @param array{'id': string, 'type': int} $collaborators
* @return array{array{'nc:collaborator': array{'id': string, 'label': string, 'type': int}}}
*/
public function setCollaborators($collaborators): array {
$this->albumMapper->setCollaborators($this->getAlbum()->getAlbum()->getId(), $collaborators);
return $this->getCollaborators();
}
}
@@ -0,0 +1,128 @@
<?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 OCA\Photos\Album\AlbumInfo;
use OCA\Photos\Album\AlbumMapper;
use OCA\Photos\Album\AlbumWithFiles;
use OCA\Photos\Service\UserConfigService;
use OCP\Files\IRootFolder;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
class AlbumsHome implements ICollection {
protected AlbumMapper $albumMapper;
protected array $principalInfo;
protected string $userId;
protected IRootFolder $rootFolder;
protected UserConfigService $userConfigService;
public const NAME = 'albums';
/**
* @var AlbumRoot[]
*/
protected ?array $children = null;
public function __construct(
array $principalInfo,
AlbumMapper $albumMapper,
string $userId,
IRootFolder $rootFolder,
UserConfigService $userConfigService
) {
$this->principalInfo = $principalInfo;
$this->albumMapper = $albumMapper;
$this->userId = $userId;
$this->rootFolder = $rootFolder;
$this->userConfigService = $userConfigService;
}
/**
* @return never
*/
public function delete() {
throw new Forbidden();
}
public function getName(): string {
return self::NAME;
}
/**
* @return never
*/
public function setName($name) {
throw new Forbidden('Permission denied to rename this folder');
}
public function createFile($name, $data = null) {
throw new Forbidden('Not allowed to create files in this folder');
}
/**
* @return void
*/
public function createDirectory($name) {
$this->albumMapper->create($this->userId, $name);
}
public function getChild($name) {
foreach ($this->getChildren() as $child) {
if ($child->getName() === $name) {
return $child;
}
}
throw new NotFound();
}
/**
* @return AlbumRoot[]
*/
public function getChildren(): array {
if ($this->children === null) {
$albumInfos = $this->albumMapper->getForUser($this->userId);
$this->children = array_map(function (AlbumInfo $albumInfo) {
return new AlbumRoot($this->albumMapper, new AlbumWithFiles($albumInfo, $this->albumMapper), $this->rootFolder, $this->userId, $this->userConfigService);
}, $albumInfos);
}
return $this->children;
}
public function childExists($name): bool {
try {
$this->getChild($name);
return true;
} catch (NotFound $e) {
return false;
}
}
public function getLastModified(): int {
return 0;
}
}
@@ -0,0 +1,39 @@
<?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 OCP\Files\NotFoundException;
use Sabre\DAV\IFile;
class PublicAlbumPhoto extends AlbumPhoto implements IFile {
/** @return void */
public function delete() {
throw new NotFoundException("Deleting photos from a public album is not allowed.");
}
/** @return void */
public function put($data) {
throw new NotFoundException("Changing a photo from a public album is not allowed.");
}
}
@@ -0,0 +1,91 @@
<?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 OCA\Photos\Album\AlbumFile;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\INode;
class PublicAlbumRoot extends AlbumRoot {
/**
* @return void
*/
public function delete() {
throw new Forbidden('Not allowed to delete a public album');
}
/**
* @return void
*/
public function setName($name) {
throw new Forbidden('Not allowed to rename a public album');
}
public function copyInto($targetName, $sourcePath, INode $sourceNode): bool {
throw new Forbidden('Not allowed to copy into a public album');
}
protected function getPhotosLocationInfo() {
$albumOwner = $this->album->getAlbum()->getUserId();
$photosLocation = $this->userConfigService->getConfigForUser($albumOwner, 'photosLocation');
$userFolder = $this->rootFolder->getUserFolder($albumOwner);
return [$photosLocation, $userFolder];
}
public function createFile($name, $data = null) {
throw new Forbidden('Not allowed to create a file in a public album');
}
protected function addFile(int $sourceId, string $ownerUID): bool {
throw new Forbidden('Not allowed to add a file to a public album');
}
// Do not reveal collaborators for public albums.
public function getCollaborators(): array {
/** @var array{array{'nc:collaborator': array{'id': string, 'label': string, 'type': int}}} */
return [];
}
public function setCollaborators($collaborators): array {
throw new Forbidden('Not allowed to collaborators a public album');
}
/** @return never */
public function getChildren(): array {
return array_map(function (AlbumFile $file) {
return new PublicAlbumPhoto($this->albumMapper, $this->album->getAlbum(), $file, $this->rootFolder, $this->rootFolder->getUserFolder($this->userId));
}, $this->album->getFiles());
}
public function getChild($name): PublicAlbumPhoto {
foreach ($this->album->getFiles() as $file) {
if ($file->getFileId() . "-" . $file->getName() === $name) {
return new PublicAlbumPhoto($this->albumMapper, $this->album->getAlbum(), $file, $this->rootFolder, $this->rootFolder->getUserFolder($this->userId));
}
}
throw new NotFound("$name not found");
}
}
@@ -0,0 +1,100 @@
<?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 OCA\Photos\Album\AlbumMapper;
use OCA\Photos\Album\AlbumWithFiles;
use OCA\Photos\Service\UserConfigService;
use OCP\Files\IRootFolder;
use OCP\IUserManager;
use Sabre\DAV\Exception\Conflict;
use Sabre\DAV\Exception\Forbidden;
class SharedAlbumRoot extends AlbumRoot {
private IUserManager $userManager;
public function __construct(
AlbumMapper $albumMapper,
AlbumWithFiles $album,
IRootFolder $rootFolder,
string $userId,
UserConfigService $userConfigService,
IUserManager $userManager
) {
parent::__construct(
$albumMapper,
$album,
$rootFolder,
$userId,
$userConfigService,
$userManager
);
$this->userManager = $userManager;
}
/**
* @return void
*/
public function delete() {
$this->albumMapper->deleteUserFromAlbumCollaboratorsList($this->userId, $this->album->getAlbum()->getId());
}
/**
* @return void
*/
public function setName($name) {
throw new Forbidden('Not allowed to rename a shared album');
}
protected function addFile(int $sourceId, string $ownerUID): bool {
if (in_array($sourceId, $this->album->getFileIds())) {
throw new Conflict("File $sourceId is already in the folder");
}
if (!$this->albumMapper->isCollaborator($this->album->getAlbum()->getId(), $this->userId)) {
return false;
}
$this->albumMapper->addFile($this->album->getAlbum()->getId(), $sourceId, $ownerUID);
return true;
}
/**
* Return only the owner, and do not reveal other collaborators.
*/
public function getCollaborators(): array {
return [[
'nc:collaborator' => [
'id' => $this->album->getAlbum()->getUserId(),
'label' => $this->userManager->get($this->album->getAlbum()->getUserId())->getDisplayName(),
'type' => $this->album->getAlbum()->getReceivedFrom(),
],
]];
}
public function setCollaborators($collaborators): array {
throw new Forbidden('Not allowed to collaborators to a public album');
}
}
@@ -0,0 +1,90 @@
<?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 OCA\Photos\Album\AlbumMapper;
use OCA\Photos\Album\AlbumWithFiles;
use OCA\Photos\Service\UserConfigService;
use OCP\Files\IRootFolder;
use OCP\IGroupManager;
use OCP\IUserManager;
use Sabre\DAV\Exception\Forbidden;
class SharedAlbumsHome extends AlbumsHome {
private IUserManager $userManager;
private IGroupManager $groupManager;
public const NAME = 'sharedalbums';
public function __construct(
array $principalInfo,
AlbumMapper $albumMapper,
string $userId,
IRootFolder $rootFolder,
IUserManager $userManager,
IGroupManager $groupManager,
UserConfigService $userConfigService
) {
parent::__construct(
$principalInfo,
$albumMapper,
$userId,
$rootFolder,
$userConfigService
);
$this->userManager = $userManager;
$this->groupManager = $groupManager;
}
/**
* @return never
*/
public function createDirectory($name) {
throw new Forbidden('Not allowed to create folders in this folder');
}
/**
* @return SharedAlbumRoot[]
*/
public function getChildren(): array {
if ($this->children === null) {
$albums = $this->albumMapper->getSharedAlbumsForCollaboratorWithFiles($this->userId, AlbumMapper::TYPE_USER);
$user = $this->userManager->get($this->userId);
$userGroups = $this->groupManager->getUserGroupIds($user);
foreach ($userGroups as $groupId) {
$albumsForGroup = $this->albumMapper->getSharedAlbumsForCollaboratorWithFiles($groupId, AlbumMapper::TYPE_GROUP);
$albumsForGroup = array_udiff($albumsForGroup, $albums, fn ($a, $b) => $a->getAlbum()->getId() - $b->getAlbum()->getId());
$albums = array_merge($albums, $albumsForGroup);
}
$this->children = array_map(function (AlbumWithFiles $album) {
return new SharedAlbumRoot($this->albumMapper, $album, $this->rootFolder, $this->userId, $this->userConfigService, $this->userManager);
}, $albums);
}
return $this->children;
}
}