]> BookStack Code Mirror - bookstack/blobdiff - app/Uploads/Controllers/ImageController.php
Thumbnails: Added OOM handling and regen endpoint
[bookstack] / app / Uploads / Controllers / ImageController.php
index 0f88b376e519f9760743853301c8d347e9136294..edf1533fad7d8a81c41b6bd5691409486c7dc945 100644 (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.
      */