X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/a6633642232efd164d4708967ab59e498fbff896..55456a57d62ff6500e48de73ba43e0e2bcbcc056:/app/Http/Controllers/Api/ChapterExportApiController.php diff --git a/app/Http/Controllers/Api/ChapterExportApiController.php b/app/Http/Controllers/Api/ChapterExportApiController.php index afdfe555d..faf5d812e 100644 --- a/app/Http/Controllers/Api/ChapterExportApiController.php +++ b/app/Http/Controllers/Api/ChapterExportApiController.php @@ -1,8 +1,9 @@ -exportFormatter = $exportFormatter; + $this->middleware('can:content-export'); } /** * Export a chapter as a PDF file. + * * @throws Throwable */ public function exportPdf(int $id) { $chapter = Chapter::visible()->findOrFail($id); $pdfContent = $this->exportFormatter->chapterToPdf($chapter); - return $this->downloadResponse($pdfContent, $chapter->slug . '.pdf'); + + return $this->download()->directly($pdfContent, $chapter->slug . '.pdf'); } /** * Export a chapter as a contained HTML file. + * * @throws Throwable */ public function exportHtml(int $id) { $chapter = Chapter::visible()->findOrFail($id); $htmlContent = $this->exportFormatter->chapterToContainedHtml($chapter); - return $this->downloadResponse($htmlContent, $chapter->slug . '.html'); + + return $this->download()->directly($htmlContent, $chapter->slug . '.html'); } /** @@ -46,6 +52,18 @@ class ChapterExportApiController extends ApiController { $chapter = Chapter::visible()->findOrFail($id); $textContent = $this->exportFormatter->chapterToPlainText($chapter); - return $this->downloadResponse($textContent, $chapter->slug . '.txt'); + + return $this->download()->directly($textContent, $chapter->slug . '.txt'); + } + + /** + * Export a chapter as a markdown file. + */ + public function exportMarkdown(int $id) + { + $chapter = Chapter::visible()->findOrFail($id); + $markdown = $this->exportFormatter->chapterToMarkdown($chapter); + + return $this->download()->directly($markdown, $chapter->slug . '.md'); } }