1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Added the ability to replace existing image files

- Updated UI with image form dropdown containing delete and replace
  image actions.
- Adds new endpoint and service/repo handling for replacing existing
  image.
- Includes tests to cover.
This commit is contained in:
Dan Brown
2023-05-28 17:32:22 +01:00
parent 9ff7c97911
commit e3c4a9d167
10 changed files with 146 additions and 36 deletions

View File

@ -14,13 +14,10 @@ use Illuminate\Validation\ValidationException;
class ImageController extends Controller
{
protected ImageRepo $imageRepo;
protected ImageService $imageService;
public function __construct(ImageRepo $imageRepo, ImageService $imageService)
{
$this->imageRepo = $imageRepo;
$this->imageService = $imageService;
public function __construct(
protected ImageRepo $imageRepo,
protected ImageService $imageService
) {
}
/**
@ -65,6 +62,29 @@ class ImageController extends Controller
]);
}
/**
* Update the file for an existing image.
*/
public function updateFile(Request $request, string $id)
{
$this->validate($request, [
'file' => ['required', 'file', ...$this->getImageValidationRules()],
]);
$image = $this->imageRepo->getById($id);
$this->checkImagePermission($image);
$this->checkOwnablePermission('image-update', $image);
$file = $request->file('file');
try {
$this->imageRepo->updateImageFile($image, $file);
} catch (ImageUploadException $exception) {
return $this->jsonError($exception->getMessage());
}
return response('');
}
/**
* Get the form for editing the given image.
*