]> BookStack Code Mirror - bookstack/blobdiff - app/Exports/Controllers/ChapterExportController.php
ZIP Exports: Built out initial import view
[bookstack] / app / Exports / Controllers / ChapterExportController.php
index d85b90dcb412d82be0d0823163ccf7ce448a4a5f..0d7a5c0d195ec94181cbacca251a632d2008e7c0 100644 (file)
@@ -5,6 +5,7 @@ namespace BookStack\Exports\Controllers;
 use BookStack\Entities\Queries\ChapterQueries;
 use BookStack\Exceptions\NotFoundException;
 use BookStack\Exports\ExportFormatter;
+use BookStack\Exports\ZipExports\ZipExportBuilder;
 use BookStack\Http\Controller;
 use Throwable;
 
@@ -70,4 +71,16 @@ class ChapterExportController extends Controller
 
         return $this->download()->directly($chapterText, $chapterSlug . '.md');
     }
+
+    /**
+     * Export a book to a contained ZIP export file.
+     * @throws NotFoundException
+     */
+    public function zip(string $bookSlug, string $chapterSlug, ZipExportBuilder $builder)
+    {
+        $chapter = $this->queries->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
+        $zip = $builder->buildForChapter($chapter);
+
+        return $this->download()->streamedDirectly(fopen($zip, 'r'), $chapterSlug . '.zip', filesize($zip));
+    }
 }