From: Dan Brown Date: Fri, 4 Jun 2021 21:59:31 +0000 (+0100) Subject: Updated base64 image extraction to use url instead of path X-Git-Tag: v21.05.1~1^2~1 X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/0627efe5e9f3ec5ef7182637e8d6a47934b3d1ab Updated base64 image extraction to use url instead of path To ensure it works with all storage types and follows the format of manually uploaded image content --- diff --git a/app/Entities/Tools/PageContent.php b/app/Entities/Tools/PageContent.php index fbee2ccb6..5e3ef98d0 100644 --- a/app/Entities/Tools/PageContent.php +++ b/app/Entities/Tools/PageContent.php @@ -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', ''); } diff --git a/app/Uploads/Image.php b/app/Uploads/Image.php index ca1df3c6c..3657aa946 100644 --- a/app/Uploads/Image.php +++ b/app/Uploads/Image.php @@ -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; diff --git a/tests/Entity/PageContentTest.php b/tests/Entity/PageContentTest.php index 670557b0c..1b3af97c7 100644 --- a/tests/Entity/PageContentTest.php +++ b/tests/Entity/PageContentTest.php @@ -495,10 +495,10 @@ class PageContentTest extends TestCase ]); $page->refresh(); - $this->assertStringMatchesFormat('%Atest%A

%A', $page->html); + $this->assertStringMatchesFormat('%Atest%A

%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('%Atest%A

%A', $page->html); + $this->assertStringMatchesFormat('%Atest%A

%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));