X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/418fd9037f445164887626fc20ea0c3b1717006d..e1b8fe45b0271e66adbcc06c7d75ddb1a80b4556:/app/Http/Controllers/Api/ChapterExportApiController.php diff --git a/app/Http/Controllers/Api/ChapterExportApiController.php b/app/Http/Controllers/Api/ChapterExportApiController.php index f19f29e9d..5715ab2e3 100644 --- a/app/Http/Controllers/Api/ChapterExportApiController.php +++ b/app/Http/Controllers/Api/ChapterExportApiController.php @@ -1,44 +1,47 @@ -chapterRepo = $chapterRepo; - $this->exportService = $exportService; - parent::__construct(); + $this->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->exportService->chapterToPdf($chapter); + $pdfContent = $this->exportFormatter->chapterToPdf($chapter); + return $this->downloadResponse($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->exportService->chapterToContainedHtml($chapter); + $htmlContent = $this->exportFormatter->chapterToContainedHtml($chapter); + return $this->downloadResponse($htmlContent, $chapter->slug . '.html'); } @@ -48,7 +51,19 @@ class ChapterExportApiController extends ApiController public function exportPlainText(int $id) { $chapter = Chapter::visible()->findOrFail($id); - $textContent = $this->exportService->chapterToPlainText($chapter); + $textContent = $this->exportFormatter->chapterToPlainText($chapter); + return $this->downloadResponse($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->downloadResponse($markdown, $chapter->slug . '.md'); + } }