X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/a87ae1601061322e7e7b2dc11658f56467761787..refs/pull/1756/head:/app/Http/Controllers/Images/DrawioImageController.php diff --git a/app/Http/Controllers/Images/DrawioImageController.php b/app/Http/Controllers/Images/DrawioImageController.php index eb0e32827..3595790f7 100644 --- a/app/Http/Controllers/Images/DrawioImageController.php +++ b/app/Http/Controllers/Images/DrawioImageController.php @@ -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) + ]); + } }