diff --git a/app/Api/ApiDocsGenerator.php b/app/Api/ApiDocsGenerator.php index a0c45608a..ddba24bdb 100644 --- a/app/Api/ApiDocsGenerator.php +++ b/app/Api/ApiDocsGenerator.php @@ -3,6 +3,7 @@ use BookStack\Http\Controllers\Api\ApiController; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Route; +use Illuminate\Support\Str; use ReflectionClass; use ReflectionException; use ReflectionMethod; @@ -117,6 +118,7 @@ class ApiDocsGenerator 'method' => $route->methods[0], 'controller' => $controller, 'controller_method' => $controllerMethod, + 'controller_method_kebab' => Str::kebab($controllerMethod), 'base_model' => $baseModelName, ]; }); diff --git a/app/Http/Controllers/Api/BooksExportApiController.php b/app/Http/Controllers/Api/BooksExportApiController.php new file mode 100644 index 000000000..605f8f408 --- /dev/null +++ b/app/Http/Controllers/Api/BooksExportApiController.php @@ -0,0 +1,55 @@ +bookRepo = $bookRepo; + $this->exportService = $exportService; + parent::__construct(); + } + + /** + * Export a book as a PDF file. + * @throws Throwable + */ + public function exportPdf(int $id) + { + $book = Book::visible()->findOrFail($id); + $pdfContent = $this->exportService->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); + return $this->downloadResponse($htmlContent, $book->slug . '.html'); + } + + /** + * Export a book as a plain text file. + */ + public function exportPlainText(int $id) + { + $book = Book::visible()->findOrFail($id); + $textContent = $this->exportService->bookToPlainText($book); + return $this->downloadResponse($textContent, $book->slug . '.txt'); + } +} diff --git a/resources/views/api-docs/index.blade.php b/resources/views/api-docs/index.blade.php index ab4db89e8..e92b505cf 100644 --- a/resources/views/api-docs/index.blade.php +++ b/resources/views/api-docs/index.blade.php @@ -26,7 +26,7 @@ {{ $endpoint['method'] }} - {{ $endpoint['controller_method'] }} + {{ $endpoint['controller_method_kebab'] }} @endforeach @@ -186,7 +186,7 @@