X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/4360da03d414cc926dde3d79e22e6e35f85838e1..refs/pull/3512/head:/app/Http/Controllers/AttachmentController.php diff --git a/app/Http/Controllers/AttachmentController.php b/app/Http/Controllers/AttachmentController.php index 477640b0a..03e362f4a 100644 --- a/app/Http/Controllers/AttachmentController.php +++ b/app/Http/Controllers/AttachmentController.php @@ -15,8 +15,8 @@ use Illuminate\Validation\ValidationException; class AttachmentController extends Controller { - protected $attachmentService; - protected $pageRepo; + protected AttachmentService $attachmentService; + protected PageRepo $pageRepo; /** * AttachmentController constructor. @@ -36,8 +36,8 @@ class AttachmentController extends Controller public function upload(Request $request) { $this->validate($request, [ - 'uploaded_to' => 'required|integer|exists:pages,id', - 'file' => 'required|file', + 'uploaded_to' => ['required', 'integer', 'exists:pages,id'], + 'file' => array_merge(['required'], $this->attachmentService->getFileValidationRules()), ]); $pageId = $request->get('uploaded_to'); @@ -65,7 +65,7 @@ class AttachmentController extends Controller public function uploadUpdate(Request $request, $attachmentId) { $this->validate($request, [ - 'file' => 'required|file', + 'file' => array_merge(['required'], $this->attachmentService->getFileValidationRules()), ]); /** @var Attachment $attachment */ @@ -111,8 +111,8 @@ class AttachmentController extends Controller try { $this->validate($request, [ - 'attachment_edit_name' => 'required|string|min:1|max:255', - 'attachment_edit_url' => 'string|min:1|max:255|safe_url', + 'attachment_edit_name' => ['required', 'string', 'min:1', 'max:255'], + 'attachment_edit_url' => ['string', 'min:1', 'max:255', 'safe_url'], ]); } catch (ValidationException $exception) { return response()->view('attachments.manager-edit-form', array_merge($request->only(['attachment_edit_name', 'attachment_edit_url']), [ @@ -146,9 +146,9 @@ class AttachmentController extends Controller try { $this->validate($request, [ - 'attachment_link_uploaded_to' => 'required|integer|exists:pages,id', - 'attachment_link_name' => 'required|string|min:1|max:255', - 'attachment_link_url' => 'required|string|min:1|max:255|safe_url', + 'attachment_link_uploaded_to' => ['required', 'integer', 'exists:pages,id'], + 'attachment_link_name' => ['required', 'string', 'min:1', 'max:255'], + 'attachment_link_url' => ['required', 'string', 'min:1', 'max:255', 'safe_url'], ]); } catch (ValidationException $exception) { return response()->view('attachments.manager-link-form', array_merge($request->only(['attachment_link_name', 'attachment_link_url']), [ @@ -173,6 +173,7 @@ class AttachmentController extends Controller /** * Get the attachments for a specific page. + * * @throws NotFoundException */ public function listForPage(int $pageId) @@ -194,7 +195,7 @@ class AttachmentController extends Controller public function sortForPage(Request $request, int $pageId) { $this->validate($request, [ - 'order' => 'required|array', + 'order' => ['required', 'array'], ]); $page = $this->pageRepo->getById($pageId); $this->checkOwnablePermission('page-update', $page); @@ -229,13 +230,13 @@ class AttachmentController extends Controller } $fileName = $attachment->getFileName(); - $attachmentContents = $this->attachmentService->getAttachmentFromStorage($attachment); + $attachmentStream = $this->attachmentService->streamAttachmentFromStorage($attachment); if ($request->get('open') === 'true') { - return $this->inlineDownloadResponse($attachmentContents, $fileName); + return $this->download()->streamedInline($attachmentStream, $fileName); } - return $this->downloadResponse($attachmentContents, $fileName); + return $this->download()->streamedDirectly($attachmentStream, $fileName); } /**