1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Thumbnails: Added OOM handling and regen endpoint

- Added some level of app out-of-memory handling so we can show a proper
  error message upon OOM events.
- Added endpoint and image-manager button/action for regenerating
  thumbnails for an image so they can be re-created upon failure.
This commit is contained in:
Dan Brown
2023-09-29 13:54:08 +01:00
parent cc0827ff28
commit 5af3041b9b
8 changed files with 138 additions and 0 deletions

View File

@ -8,6 +8,7 @@ use BookStack\Http\Controller;
use BookStack\Uploads\Image;
use BookStack\Uploads\ImageRepo;
use BookStack\Uploads\ImageService;
use BookStack\Util\OutOfMemoryHandler;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
@ -121,6 +122,24 @@ class ImageController extends Controller
return response('');
}
/**
* Rebuild the thumbnails for the given image.
*/
public function rebuildThumbnails(string $id)
{
$image = $this->imageRepo->getById($id);
$this->checkImagePermission($image);
$this->checkOwnablePermission('image-update', $image);
new OutOfMemoryHandler(function () {
return $this->jsonError(trans('errors.image_thumbnail_memory_limit'));
});
$this->imageRepo->loadThumbs($image, true);
return response(trans('components.image_rebuild_thumbs_success'));
}
/**
* Check related page permission and ensure type is drawio or gallery.
*/