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:
@ -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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user