/**
* Parse a base64 image URI into the data and extension.
+ *
* @return array{extension: array, data: string}
*/
protected function parseBase64ImageUri(string $uri): array
{
[$dataDefinition, $base64ImageData] = explode(',', $uri, 2);
$extension = strtolower(preg_split('/[\/;]/', $dataDefinition)[1] ?? '');
+
return [
'extension' => $extension,
- 'data' => base64_decode($base64ImageData) ?: '',
+ 'data' => base64_decode($base64ImageData) ?: '',
];
}
/**
* Get the attachments for a specific page.
+ *
* @throws NotFoundException
*/
public function listForPage(int $pageId)
use BookStack\Interfaces\Loggable;
use BookStack\Model;
use BookStack\Util\WebSafeMimeSniffer;
-use finfo;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Exceptions\HttpResponseException;
*/
protected function inlineDownloadResponse(string $content, string $fileName): Response
{
-
- $mime = (new WebSafeMimeSniffer)->sniff($content);
+ $mime = (new WebSafeMimeSniffer())->sniff($content);
return response()->make($content, 200, [
'Content-Type' => $mime,
{
Validator::extend('image_extension', function ($attribute, $value, $parameters, $validator) {
$extension = strtolower($value->getClientOriginalExtension());
+
return ImageService::isExtensionSupported($extension);
});
/**
* ImageRepo constructor.
*/
- public function __construct(ImageService $imageService, PermissionService $permissionService) {
+ public function __construct(ImageService $imageService, PermissionService $permissionService)
+ {
$this->imageService = $imageService;
$this->restrictionService = $permissionService;
}
* Get the thumbnail for an image.
* If $keepRatio is true only the width will be used.
* Checks the cache then storage to avoid creating / accessing the filesystem on every check.
+ *
* @throws Exception
* @throws InvalidArgumentException
*/
{
try {
$thumb = $this->imageTool->make($imageData);
- } catch (ErrorException | NotSupportedException $e) {
+ } catch (ErrorException|NotSupportedException $e) {
throw new ImageUploadException(trans('errors.cannot_create_thumbs'));
}
public function streamImageFromStorageResponse(string $imageType, string $path): StreamedResponse
{
$disk = $this->getStorageDisk($imageType);
+
return $disk->response($path);
}
*/
class WebSafeMimeSniffer
{
-
/**
* @var string[]
*/
return 'application/octet-stream';
}
-
-}
\ No newline at end of file
+}
}
/**
- * @return Array<User, string, TestResponse>
+ * @return array<User, string, TestResponse>
*/
protected function startTotpLogin(): array
{
}
/**
- * @return Array<User, string, TestResponse>
+ * @return array<User, string, TestResponse>
*/
protected function startBackupCodeLogin($codes = ['kzzu6-1pgll', 'bzxnf-plygd', 'bwdsp-ysl51', '1vo93-ioy7n', 'lf7nw-wdyka', 'xmtrd-oplac']): array
{
$page->refresh();
$this->assertStringContainsString('<img src=""', $page->html);
}
-
}
public function test_base64_images_get_extracted_from_markdown_page_content()
use BookStack\Uploads\AttachmentService;
use Illuminate\Http\UploadedFile;
use Tests\TestCase;
-use Tests\TestResponse;
class AttachmentTest extends TestCase
{
$upload = new UploadedFile($filePath, $filename, $mimeType, null, true);
$this->call('POST', '/attachments/upload', ['uploaded_to' => $page->id], [], ['file' => $upload], []);
+
return $page->attachments()->latest()->firstOrFail();
}
$this->deleteUploads();
}
-
}