]> BookStack Code Mirror - bookstack/blobdiff - app/Exports/Controllers/BookExportController.php
ZIP Exports: Added entity cross refs, Started export tests
[bookstack] / app / Exports / Controllers / BookExportController.php
index 36906b6ad7bbad35de90b48304709f2dc1416769..f726175a086acab697ce6e05575f69f90b58be8f 100644 (file)
@@ -3,7 +3,9 @@
 namespace BookStack\Exports\Controllers;
 
 use BookStack\Entities\Queries\BookQueries;
+use BookStack\Exceptions\NotFoundException;
 use BookStack\Exports\ExportFormatter;
+use BookStack\Exports\ZipExports\ZipExportBuilder;
 use BookStack\Http\Controller;
 use Throwable;
 
@@ -63,4 +65,16 @@ class BookExportController extends Controller
 
         return $this->download()->directly($textContent, $bookSlug . '.md');
     }
+
+    /**
+     * Export a book to a contained ZIP export file.
+     * @throws NotFoundException
+     */
+    public function zip(string $bookSlug, ZipExportBuilder $builder)
+    {
+        $book = $this->queries->findVisibleBySlugOrFail($bookSlug);
+        $zip = $builder->buildForBook($book);
+
+        return $this->download()->streamedDirectly(fopen($zip, 'r'), $bookSlug . '.zip', filesize($zip));
+    }
 }