X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/8a6cf0cdecf8596c7cd4809188712f575c9e8202..f28daa01d9d43d36c12b075bddca92be9e8f85e4:/app/Http/Controllers/Api/BookExportApiController.php diff --git a/app/Http/Controllers/Api/BookExportApiController.php b/app/Http/Controllers/Api/BookExportApiController.php index 31fe5250f..028bc3a81 100644 --- a/app/Http/Controllers/Api/BookExportApiController.php +++ b/app/Http/Controllers/Api/BookExportApiController.php @@ -1,44 +1,44 @@ -bookRepo = $bookRepo; - $this->exportService = $exportService; - parent::__construct(); + $this->exportFormatter = $exportFormatter; + $this->middleware('can:content-export'); } /** * Export a book as a PDF file. + * * @throws Throwable */ public function exportPdf(int $id) { $book = Book::visible()->findOrFail($id); - $pdfContent = $this->exportService->bookToPdf($book); + $pdfContent = $this->exportFormatter->bookToPdf($book); + return $this->downloadResponse($pdfContent, $book->slug . '.pdf'); } /** * Export a book as a contained HTML file. + * * @throws Throwable */ public function exportHtml(int $id) { $book = Book::visible()->findOrFail($id); - $htmlContent = $this->exportService->bookToContainedHtml($book); + $htmlContent = $this->exportFormatter->bookToContainedHtml($book); + return $this->downloadResponse($htmlContent, $book->slug . '.html'); } @@ -48,7 +48,19 @@ class BookExportApiController extends ApiController public function exportPlainText(int $id) { $book = Book::visible()->findOrFail($id); - $textContent = $this->exportService->bookToPlainText($book); + $textContent = $this->exportFormatter->bookToPlainText($book); + return $this->downloadResponse($textContent, $book->slug . '.txt'); } + + /** + * Export a book as a markdown file. + */ + public function exportMarkdown(int $id) + { + $book = Book::visible()->findOrFail($id); + $markdown = $this->exportFormatter->bookToMarkdown($book); + + return $this->downloadResponse($markdown, $book->slug . '.md'); + } }