X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/8a6cf0cdecf8596c7cd4809188712f575c9e8202..f28daa01d9d43d36c12b075bddca92be9e8f85e4:/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'); + } }