]> BookStack Code Mirror - bookstack/commitdiff
Updated base64 image extraction to use url instead of path
authorDan Brown <redacted>
Fri, 4 Jun 2021 21:59:31 +0000 (22:59 +0100)
committerDan Brown <redacted>
Fri, 4 Jun 2021 21:59:31 +0000 (22:59 +0100)
To ensure it works with all storage types and follows the format of
manually uploaded image content

app/Entities/Tools/PageContent.php
app/Uploads/Image.php
tests/Entity/PageContentTest.php

index fbee2ccb64385fb324f5d21a7a047a6120d4394c..5e3ef98d0fa7b336d2195cd3eaf3a4550516827b 100644 (file)
@@ -99,7 +99,7 @@ class PageContent
             $imageName = 'embedded-image-' . Str::random(8) . '.' . $extension;
             try {
                 $image = $imageRepo->saveNewFromData($imageName, base64_decode($base64ImageData), 'gallery', $page->id);
-                $imageNode->setAttribute('src', $image->path);
+                $imageNode->setAttribute('src', $image->url);
             } catch (ImageUploadException $exception) {
                 $imageNode->setAttribute('src', '');
             }
index ca1df3c6c5e209da107bfaaa9a0829e34cb8190c..3657aa9469d2bac249fe0b146608a4784ba96eef 100644 (file)
@@ -4,6 +4,16 @@ use BookStack\Entities\Models\Page;
 use BookStack\Model;
 use BookStack\Traits\HasCreatorAndUpdater;
 
+/**
+ * @property int $id
+ * @property string $name
+ * @property string $url
+ * @property string $path
+ * @property string $type
+ * @property int $uploaded_to
+ * @property int $created_by
+ * @property int $updated_by
+ */
 class Image extends Model
 {
     use HasCreatorAndUpdater;
index 670557b0c8f841f67c0ca82281e0cc92ae45e431..1b3af97c7c836de91dec418c5e78de57ecbd6233 100644 (file)
@@ -495,10 +495,10 @@ class PageContentTest extends TestCase
         ]);
 
         $page->refresh();
-        $this->assertStringMatchesFormat('%A<p%A>test<img src="/uploads/images/gallery/%A.jpeg">%A</p>%A', $page->html);
+        $this->assertStringMatchesFormat('%A<p%A>test<img src="http://localhost/uploads/images/gallery/%A.jpeg">%A</p>%A', $page->html);
 
         $matches = [];
-        preg_match('/src="(.*?)"/', $page->html, $matches);
+        preg_match('/src="https:\/\/p.rizon.top:443\/http\/localhost(.*?)"/', $page->html, $matches);
         $imagePath = $matches[1];
         $imageFile = public_path($imagePath);
         $this->assertEquals(base64_decode($this->base64Jpeg), file_get_contents($imageFile));
@@ -519,10 +519,10 @@ class PageContentTest extends TestCase
         ]);
 
         $page->refresh();
-        $this->assertStringMatchesFormat('%A<p%A>test<img src="/uploads/images/gallery/%A.png">%A</p>%A', $page->html);
+        $this->assertStringMatchesFormat('%A<p%A>test<img src="http://localhost/uploads/images/gallery/%A.png">%A</p>%A', $page->html);
 
         $matches = [];
-        preg_match('/src="(.*?)"/', $page->html, $matches);
+        preg_match('/src="https:\/\/p.rizon.top:443\/http\/localhost(.*?)"/', $page->html, $matches);
         $imagePath = $matches[1];
         $imageFile = public_path($imagePath);
         $this->assertEquals(base64_decode($base64PngWithoutWhitespace), file_get_contents($imageFile));