]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/Images/DrawioImageController.php
Add the "Create Shelf" resp. "Create Book" to the home view
[bookstack] / app / Http / Controllers / Images / DrawioImageController.php
index eb0e328277b9d1b75dd98eb0263ca8406a393e2d..3595790f71d5e557760601205ba683468c04d531 100644 (file)
@@ -64,4 +64,25 @@ class DrawioImageController extends Controller
         return response()->json($image);
     }
 
+    /**
+     * Get the content of an image based64 encoded.
+     * @param $id
+     * @return \Illuminate\Http\JsonResponse|mixed
+     */
+    public function getAsBase64($id)
+    {
+        $image = $this->imageRepo->getById($id);
+        $page = $image->getPage();
+        if ($image === null || $image->type !== 'drawio' || !userCan('page-view', $page)) {
+            return $this->jsonError("Image data could not be found");
+        }
+
+        $imageData = $this->imageRepo->getImageData($image);
+        if ($imageData === null) {
+            return $this->jsonError("Image data could not be found");
+        }
+        return response()->json([
+            'content' => base64_encode($imageData)
+        ]);
+    }
 }