]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/Images/DrawioImageController.php
Replaced embeds with images in exports
[bookstack] / app / Http / Controllers / Images / DrawioImageController.php
index d99bb8e6f6acbb080712e8089bdfe7cfb4e2c36c..31c375c25beee3500c0e439b6a4a0c78262403aa 100644 (file)
@@ -44,8 +44,8 @@ class DrawioImageController extends Controller
     public function create(Request $request)
     {
         $this->validate($request, [
-            'image'       => 'required|string',
-            'uploaded_to' => 'required|integer',
+            'image'       => ['required', 'string'],
+            'uploaded_to' => ['required', 'integer'],
         ]);
 
         $this->checkPermission('image-create-all');
@@ -67,18 +67,20 @@ class DrawioImageController extends Controller
     public function getAsBase64($id)
     {
         $image = $this->imageRepo->getById($id);
-        $page = $image->getPage();
-        if ($image === null || $image->type !== 'drawio' || !userCan('page-view', $page)) {
+        if (is_null($image) || $image->type !== 'drawio' || !userCan('page-view', $image->getPage())) {
             return $this->jsonError('Image data could not be found');
         }
 
         $imageData = $this->imageRepo->getImageData($image);
-        if ($imageData === null) {
+        if (is_null($imageData)) {
             return $this->jsonError('Image data could not be found');
         }
 
+        $isSvg = strtolower(pathinfo($image->path, PATHINFO_EXTENSION)) === 'svg';
+        $uriPrefix = $isSvg ? 'data:image/svg+xml;base64,' : 'data:image/png;base64,';
+
         return response()->json([
-            'content' => base64_encode($imageData),
+            'content' => $uriPrefix . base64_encode($imageData),
         ]);
     }
 }