diff options
author | Julien Veyssier <eneiluj@posteo.net> | 2021-12-28 14:22:03 +0300 |
---|---|---|
committer | Julien Veyssier <eneiluj@posteo.net> | 2022-01-03 12:27:38 +0300 |
commit | dc710f7e99ebf7695504dfa3f66000ecdcb93560 (patch) | |
tree | 397d1b0211e9d514a466a51ae39561f93ffa1a5a /lib | |
parent | 390585217256d316cbc4369bf88f8f16dd730154 (diff) |
fix other stuff after PR comments
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/ImageController.php | 4 | ||||
-rw-r--r-- | lib/Service/ImageService.php | 31 |
2 files changed, 28 insertions, 7 deletions
diff --git a/lib/Controller/ImageController.php b/lib/Controller/ImageController.php index fc2e1a4bd..c29e5f1f7 100644 --- a/lib/Controller/ImageController.php +++ b/lib/Controller/ImageController.php @@ -197,11 +197,11 @@ class ImageController extends Controller { * @param int $documentId * @param int $sessionId * @param string $sessionToken - * @param string|null $shareToken * @param string $imageFileName + * @param string|null $shareToken * @return DataDisplayResponse */ - public function getImage(int $documentId, int $sessionId, string $sessionToken, ?string $shareToken = null, string $imageFileName): DataDisplayResponse { + public function getImage(int $documentId, int $sessionId, string $sessionToken, string $imageFileName, ?string $shareToken = null): DataDisplayResponse { if (!$this->sessionService->isValidSession($documentId, $sessionId, $sessionToken)) { return new DataDisplayResponse('', Http::STATUS_NOT_FOUND); } diff --git a/lib/Service/ImageService.php b/lib/Service/ImageService.php index 778be8c82..8ba791a05 100644 --- a/lib/Service/ImageService.php +++ b/lib/Service/ImageService.php @@ -410,6 +410,14 @@ class ImageService { return null; } + /** + * @param File $textFile + * @return Folder|null + * @throws NotFoundException + * @throws NotPermittedException + * @throws \OCP\Files\InvalidPathException + * @throws \OC\User\NoUserException + */ private function getAttachmentDirectoryForFile(File $textFile): ?Folder { $owner = $textFile->getOwner(); $ownerId = $owner->getUID(); @@ -487,7 +495,7 @@ class ImageService { if ($textFile instanceof File) { return $textFile; } - } elseif ($share->getNodeType() === 'folder' && $documentId !== null) { + } elseif ($documentId !== null && $share->getNodeType() === 'folder') { $folder = $share->getNode(); if ($folder instanceof Folder) { $textFile = $folder->getById($documentId); @@ -568,7 +576,10 @@ class ImageService { $textFile = $textFile[0]; if ($textFile->getMimeType() === 'text/markdown') { // get IDs of the files inside the attachment dir - $attachmentDir = $this->getOrCreateAttachmentDirectoryForFile($textFile); + $attachmentDir = $this->getAttachmentDirectoryForFile($textFile); + if ($attachmentDir === null) { + return 0; + } $attachmentsByName = []; foreach ($attachmentDir->getDirectoryListing() as $attNode) { $attachmentsByName[$attNode->getName()] = $attNode; @@ -601,7 +612,7 @@ class ImageService { $matches, PREG_SET_ORDER ); - return array_map(function (array $match) { + return array_map(static function (array $match) { return $match[1] ?? null; }, $matches); } @@ -610,8 +621,8 @@ class ImageService { * @param File $source * @param File $target * @throws NotFoundException + * @throws NotPermittedException * @throws \OCP\Files\InvalidPathException - * @throws \OCP\Files\NotPermittedException * @throws \OCP\Lock\LockedException */ public function moveAttachments(File $source, File $target): void { @@ -620,6 +631,7 @@ class ImageService { $sourceAttachmentDir = $this->getAttachmentDirectoryForFile($source); // if there is an attachment dir for this file // and it is in the same directory as the source file + // in other words, we move the attachment dir only if the .md file is moved by its owner if ($sourceAttachmentDir !== null && $source->getParent()->getId() === $sourceAttachmentDir->getParent()->getId() ) { @@ -631,8 +643,8 @@ class ImageService { /** * @param File $source * @throws NotFoundException + * @throws NotPermittedException * @throws \OCP\Files\InvalidPathException - * @throws \OCP\Files\NotPermittedException */ public function deleteAttachments(File $source): void { // if there is an attachment dir for this file @@ -642,6 +654,15 @@ class ImageService { } } + /** + * @param File $source + * @param File $target + * @return void + * @throws NotFoundException + * @throws NotPermittedException + * @throws \OCP\Files\InvalidPathException + * @throws \OCP\Lock\LockedException + */ public function copyAttachments(File $source, File $target): void { $sourceAttachmentDir = $this->getAttachmentDirectoryForFile($source); if ($sourceAttachmentDir !== null) { |