X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/141eecb858cce126452baeb16905e25b6ceb13c6..refs/pull/4389/head:/app/Uploads/Controllers/ImageGalleryApiController.php diff --git a/app/Uploads/Controllers/ImageGalleryApiController.php b/app/Uploads/Controllers/ImageGalleryApiController.php index 1614b6445..0d35d2905 100644 --- a/app/Uploads/Controllers/ImageGalleryApiController.php +++ b/app/Uploads/Controllers/ImageGalleryApiController.php @@ -30,6 +30,7 @@ class ImageGalleryApiController extends ApiController ], 'update' => [ 'name' => ['string', 'max:180'], + 'image' => ['file', ...$this->getImageValidationRules()], ] ]; } @@ -51,8 +52,10 @@ class ImageGalleryApiController extends ApiController /** * Create a new image in the system. + * * Since "image" is expected to be a file, this needs to be a 'multipart/form-data' type request. * The provided "uploaded_to" should be an existing page ID in the system. + * * If the "name" parameter is omitted, the filename of the provided image file will be used instead. * The "type" parameter should be 'gallery' for page content images, and 'drawio' should only be used * when the file is a PNG file with diagrams.net image data embedded within. @@ -89,7 +92,8 @@ class ImageGalleryApiController extends ApiController /** * Update the details of an existing image in the system. - * Only allows updating of the image name at this time. + * Since "image" is expected to be a file, this needs to be a 'multipart/form-data' type request if providing a + * new image file. Updated image files should be of the same file type as the original image. */ public function update(Request $request, string $id) { @@ -99,6 +103,9 @@ class ImageGalleryApiController extends ApiController $this->checkOwnablePermission('image-update', $image); $this->imageRepo->updateImageDetails($image, $data); + if (isset($data['image'])) { + $this->imageRepo->updateImageFile($image, $data['image']); + } return response()->json($this->formatForSingleResponse($image)); } @@ -124,7 +131,7 @@ class ImageGalleryApiController extends ApiController protected function formatForSingleResponse(Image $image): array { $this->imageRepo->loadThumbs($image); - $data = $image->getAttributes(); + $data = $image->toArray(); $data['created_by'] = $image->createdBy; $data['updated_by'] = $image->updatedBy; $data['content'] = [];