]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/BookExportController.php
move zip export into exportservice
[bookstack] / app / Http / Controllers / BookExportController.php
1 <?php
2
3 namespace BookStack\Http\Controllers;
4
5 use BookStack\Entities\Managers\BookContents;
6 use BookStack\Entities\ExportService;
7 use BookStack\Entities\Repos\BookRepo;
8 use Throwable;
9
10 class BookExportController extends Controller
11 {
12
13     protected $bookRepo;
14     protected $exportService;
15
16     /**
17      * BookExportController constructor.
18      */
19     public function __construct(BookRepo $bookRepo, ExportService $exportService)
20     {
21         $this->bookRepo = $bookRepo;
22         $this->exportService = $exportService;
23         parent::__construct();
24     }
25
26     /**
27      * Export a book as a PDF file.
28      * @throws Throwable
29      */
30     public function pdf(string $bookSlug)
31     {
32         $book = $this->bookRepo->getBySlug($bookSlug);
33         $pdfContent = $this->exportService->bookToPdf($book);
34         return $this->downloadResponse($pdfContent, $bookSlug . '.pdf');
35     }
36
37     /**
38      * Export a book as a contained HTML file.
39      * @throws Throwable
40      */
41     public function html(string $bookSlug)
42     {
43         $book = $this->bookRepo->getBySlug($bookSlug);
44         $htmlContent = $this->exportService->bookToContainedHtml($book);
45         return $this->downloadResponse($htmlContent, $bookSlug . '.html');
46     }
47
48     /**
49      * Export a book as a plain text file.
50      */
51     public function plainText(string $bookSlug)
52     {
53         $book = $this->bookRepo->getBySlug($bookSlug);
54         $textContent = $this->exportService->bookToPlainText($book);
55         return $this->downloadResponse($textContent, $bookSlug . '.txt');
56     }
57
58     /**
59      * Export a book as a markdown file.
60      */
61     public function markdown(string $bookSlug)
62     {
63         $book = $this->bookRepo->getBySlug($bookSlug);
64         $textContent = $this->exportService->bookToMarkdown($book);
65         return $this->downloadResponse($textContent, $bookSlug . '.md');
66     }
67
68     /**
69      * Export a book as a zip file, made of markdown files.
70      */
71     public function zip(string $bookSlug)
72     {
73         $book = $this->bookRepo->getBySlug($bookSlug);
74         $filename = $this->exportService->bookToZip($book);
75         return response()->download($filename);
76     }
77 }