]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/ImageController.php
Drawings now generate revisions, not replace
[bookstack] / app / Http / Controllers / ImageController.php
index 8437c80d71d1ac58b1565fcc56fc66be45a63af0..b156a84255a6492ac11217bab7eea1ed28e35707 100644 (file)
@@ -170,7 +170,7 @@ class ImageController extends Controller
      * @param Request $request
      * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
      */
-    public function replaceDrawing(string $id, Request $request)
+    public function updateDrawing(string $id, Request $request)
     {
         $this->validate($request, [
             'image' => 'required|string'
@@ -182,7 +182,7 @@ class ImageController extends Controller
         $this->checkOwnablePermission('image-update', $image);
 
         try {
-            $image = $this->imageRepo->replaceDrawingContent($image, $imageBase64Data);
+            $image = $this->imageRepo->updateDrawing($image, $imageBase64Data);
         } catch (ImageUploadException $e) {
             return response($e->getMessage(), 500);
         }
@@ -245,26 +245,28 @@ class ImageController extends Controller
     }
 
     /**
-     * Deletes an image and all thumbnail/image files
+     * Show the usage of an image on pages.
      * @param EntityRepo $entityRepo
-     * @param Request $request
+     * @param $id
+     * @return \Illuminate\Http\JsonResponse
+     */
+    public function usage(EntityRepo $entityRepo, $id)
+    {
+        $image = $this->imageRepo->getById($id);
+        $pageSearch = $entityRepo->searchForImage($image->url);
+        return response()->json($pageSearch);
+    }
+
+    /**
+     * Deletes an image and all thumbnail/image files
      * @param int $id
      * @return \Illuminate\Http\JsonResponse
      */
-    public function destroy(EntityRepo $entityRepo, Request $request, $id)
+    public function destroy($id)
     {
         $image = $this->imageRepo->getById($id);
         $this->checkOwnablePermission('image-delete', $image);
 
-        // Check if this image is used on any pages
-        $isForced = in_array($request->get('force', ''), [true, 'true']);
-        if (!$isForced) {
-            $pageSearch = $entityRepo->searchForImage($image->url);
-            if ($pageSearch !== false) {
-                return response()->json($pageSearch, 400);
-            }
-        }
-
         $this->imageRepo->destroyImage($image);
         return response()->json(trans('components.images_deleted'));
     }