]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/BookExportController.php
move zip export into exportservice
[bookstack] / app / Http / Controllers / BookExportController.php
index ae3f56b816f5dc4368ec9a4242c6ed03346f2b25..a92d94cc94f4f7a0b368dfb47b2a13f7009c8848 100644 (file)
@@ -2,27 +2,19 @@
 
 namespace BookStack\Http\Controllers;
 
+use BookStack\Entities\Managers\BookContents;
 use BookStack\Entities\ExportService;
 use BookStack\Entities\Repos\BookRepo;
-use BookStack\Exceptions\NotFoundException;
 use Throwable;
 
 class BookExportController extends Controller
 {
-    /**
-     * @var BookRepo
-     */
-    protected $bookRepo;
 
-    /**
-     * @var ExportService
-     */
+    protected $bookRepo;
     protected $exportService;
 
     /**
      * BookExportController constructor.
-     * @param BookRepo $bookRepo
-     * @param ExportService $exportService
      */
     public function __construct(BookRepo $bookRepo, ExportService $exportService)
     {
@@ -33,9 +25,6 @@ class BookExportController extends Controller
 
     /**
      * Export a book as a PDF file.
-     * @param string $bookSlug
-     * @return mixed
-     * @throws NotFoundException
      * @throws Throwable
      */
     public function pdf(string $bookSlug)
@@ -47,9 +36,6 @@ class BookExportController extends Controller
 
     /**
      * Export a book as a contained HTML file.
-     * @param string $bookSlug
-     * @return mixed
-     * @throws NotFoundException
      * @throws Throwable
      */
     public function html(string $bookSlug)
@@ -61,9 +47,6 @@ class BookExportController extends Controller
 
     /**
      * Export a book as a plain text file.
-     * @param $bookSlug
-     * @return mixed
-     * @throws NotFoundException
      */
     public function plainText(string $bookSlug)
     {
@@ -71,4 +54,24 @@ class BookExportController extends Controller
         $textContent = $this->exportService->bookToPlainText($book);
         return $this->downloadResponse($textContent, $bookSlug . '.txt');
     }
+
+    /**
+     * Export a book as a markdown file.
+     */
+    public function markdown(string $bookSlug)
+    {
+        $book = $this->bookRepo->getBySlug($bookSlug);
+        $textContent = $this->exportService->bookToMarkdown($book);
+        return $this->downloadResponse($textContent, $bookSlug . '.md');
+    }
+
+    /**
+     * Export a book as a zip file, made of markdown files.
+     */
+    public function zip(string $bookSlug)
+    {
+        $book = $this->bookRepo->getBySlug($bookSlug);
+        $filename = $this->exportService->bookToZip($book);
+        return response()->download($filename);
+    }
 }