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

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJulien Veyssier <eneiluj@posteo.net>2021-10-22 17:39:13 +0300
committerJulien Veyssier <eneiluj@posteo.net>2022-01-03 12:27:34 +0300
commit849b4f050569297ebbd8f9630f569dcb86fcbe60 (patch)
tree1b75f6259eba68d6ce327692e7a8393d1eb249e3 /lib
parent7267f0b71d931ee9c464c1607cf9f5ed7a1a7e87 (diff)
identify image by name instead of id in text file content
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/ImageController.php4
-rw-r--r--lib/Service/ImageService.php25
2 files changed, 14 insertions, 15 deletions
diff --git a/lib/Controller/ImageController.php b/lib/Controller/ImageController.php
index 91bafa925..435b09559 100644
--- a/lib/Controller/ImageController.php
+++ b/lib/Controller/ImageController.php
@@ -89,8 +89,8 @@ class ImageController extends Controller {
* @NoAdminRequired
* @NoCSRFRequired
*/
- public function getImage(int $textFileId, int $imageFileId): DataDisplayResponse {
- $imageContent = $this->imageService->getImage($textFileId, $imageFileId, $this->userId);
+ public function getImage(int $textFileId, string $imageFileName): DataDisplayResponse {
+ $imageContent = $this->imageService->getImage($textFileId, $imageFileName, $this->userId);
if ($imageContent !== null) {
return new DataDisplayResponse($imageContent);
} else {
diff --git a/lib/Service/ImageService.php b/lib/Service/ImageService.php
index 3075ef5b8..0c3c06985 100644
--- a/lib/Service/ImageService.php
+++ b/lib/Service/ImageService.php
@@ -29,6 +29,7 @@ namespace OCA\Text\Service;
use Exception;
use OCP\Files\Folder;
use OCP\Files\File;
+use OCP\Files\NotFoundException;
use Throwable;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ConnectException;
@@ -72,27 +73,25 @@ class ImageService {
/**
* @param int $textFileId
- * @param int $imageFileId
+ * @param string $imageFileName
* @param string $userId
* @return string|null
- * @throws \OCP\Files\NotFoundException
+ * @throws NotFoundException
+ * @throws \OCP\Files\InvalidPathException
* @throws \OCP\Files\NotPermittedException
* @throws \OCP\Lock\LockedException
* @throws \OC\User\NoUserException
*/
- public function getImage(int $textFileId, int $imageFileId, string $userId): ?string {
- error_log('ImageService::getImage');
+ public function getImage(int $textFileId, string $imageFileName, string $userId): ?string {
$attachmentFolder = $this->getOrCreateAttachmentDirectory($textFileId, $userId);
if ($attachmentFolder !== null) {
- error_log('ATT OK');
- $imageFile = $attachmentFolder->getById($imageFileId);
- if (count($imageFile) > 0) {
- error_log('IMG file found');
- $imageFile = $imageFile[0];
- if ($imageFile instanceof File) {
- error_log('IMG IS FILE');
- return $imageFile->getContent();
- }
+ try {
+ $imageFile = $attachmentFolder->get($imageFileName);
+ } catch (NotFoundException $e) {
+ return null;
+ }
+ if ($imageFile instanceof File) {
+ return $imageFile->getContent();
}
}
return null;