mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-09 10:22:51 +03:00
Images: Started refactor of image service
To break it up. Also added better memory handling to other parts of the app.
This commit is contained in:
@@ -10,11 +10,9 @@ use Illuminate\Http\Request;
|
||||
|
||||
class DrawioImageController extends Controller
|
||||
{
|
||||
protected $imageRepo;
|
||||
|
||||
public function __construct(ImageRepo $imageRepo)
|
||||
{
|
||||
$this->imageRepo = $imageRepo;
|
||||
public function __construct(
|
||||
protected ImageRepo $imageRepo
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -5,6 +5,7 @@ namespace BookStack\Uploads\Controllers;
|
||||
use BookStack\Exceptions\ImageUploadException;
|
||||
use BookStack\Http\Controller;
|
||||
use BookStack\Uploads\ImageRepo;
|
||||
use BookStack\Util\OutOfMemoryHandler;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -53,6 +54,10 @@ class GalleryImageController extends Controller
|
||||
return $this->jsonError(implode("\n", $exception->errors()['file']));
|
||||
}
|
||||
|
||||
new OutOfMemoryHandler(function () {
|
||||
return $this->jsonError(trans('errors.image_upload_memory_limit'));
|
||||
});
|
||||
|
||||
try {
|
||||
$imageUpload = $request->file('file');
|
||||
$uploadedTo = $request->get('uploaded_to', 0);
|
||||
|
@@ -11,7 +11,6 @@ use BookStack\Uploads\ImageService;
|
||||
use BookStack\Util\OutOfMemoryHandler;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class ImageController extends Controller
|
||||
{
|
||||
@@ -39,9 +38,6 @@ class ImageController extends Controller
|
||||
|
||||
/**
|
||||
* Update image details.
|
||||
*
|
||||
* @throws ImageUploadException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
@@ -75,6 +71,10 @@ class ImageController extends Controller
|
||||
$this->checkOwnablePermission('image-update', $image);
|
||||
$file = $request->file('file');
|
||||
|
||||
new OutOfMemoryHandler(function () {
|
||||
return $this->jsonError(trans('errors.image_upload_memory_limit'));
|
||||
});
|
||||
|
||||
try {
|
||||
$this->imageRepo->updateImageFile($image, $file);
|
||||
} catch (ImageUploadException $exception) {
|
||||
|
Reference in New Issue
Block a user