mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Implement functionality to export a book, along with its pages and chapters, as a ZIP file.
This commit is contained in:
@ -4,6 +4,7 @@ namespace BookStack\Exports\Controllers;
|
|||||||
|
|
||||||
use BookStack\Entities\Queries\BookQueries;
|
use BookStack\Entities\Queries\BookQueries;
|
||||||
use BookStack\Exports\ExportFormatter;
|
use BookStack\Exports\ExportFormatter;
|
||||||
|
use BookStack\Exports\ZipExports\ZipExportBuilder;
|
||||||
use BookStack\Http\ApiController;
|
use BookStack\Http\ApiController;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
@ -63,4 +64,19 @@ class BookExportApiController extends ApiController
|
|||||||
|
|
||||||
return $this->download()->directly($markdown, $book->slug . '.md');
|
return $this->download()->directly($markdown, $book->slug . '.md');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export a book to a contained ZIP export file.
|
||||||
|
* @throws NotFoundException
|
||||||
|
*/
|
||||||
|
public function exportZip(int $id, ZipExportBuilder $builder)
|
||||||
|
{
|
||||||
|
$book = $this->queries->findVisibleByIdOrFail($id);
|
||||||
|
$bookName= $book->getShortName();
|
||||||
|
|
||||||
|
$zip = $builder->buildForBook($book);
|
||||||
|
|
||||||
|
return $this->download()->streamedFileDirectly($zip, $bookName . '.zip', filesize($zip), true);
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ namespace BookStack\Exports\Controllers;
|
|||||||
|
|
||||||
use BookStack\Entities\Queries\ChapterQueries;
|
use BookStack\Entities\Queries\ChapterQueries;
|
||||||
use BookStack\Exports\ExportFormatter;
|
use BookStack\Exports\ExportFormatter;
|
||||||
|
use BookStack\Exports\ZipExports\ZipExportBuilder;
|
||||||
use BookStack\Http\ApiController;
|
use BookStack\Http\ApiController;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
@ -63,4 +64,13 @@ class ChapterExportApiController extends ApiController
|
|||||||
|
|
||||||
return $this->download()->directly($markdown, $chapter->slug . '.md');
|
return $this->download()->directly($markdown, $chapter->slug . '.md');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public function exportZip(int $id, ZipExportBuilder $builder)
|
||||||
|
{
|
||||||
|
$chapter = $this->queries->findVisibleByIdOrFail($id);
|
||||||
|
$chapterName= $chapter->getShortName();
|
||||||
|
$zip = $builder->buildForChapter($chapter);
|
||||||
|
|
||||||
|
return $this->download()->streamedFileDirectly($zip, $chapterName . '.zip', filesize($zip), true);
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ namespace BookStack\Exports\Controllers;
|
|||||||
|
|
||||||
use BookStack\Entities\Queries\PageQueries;
|
use BookStack\Entities\Queries\PageQueries;
|
||||||
use BookStack\Exports\ExportFormatter;
|
use BookStack\Exports\ExportFormatter;
|
||||||
|
use BookStack\Exports\ZipExports\ZipExportBuilder;
|
||||||
use BookStack\Http\ApiController;
|
use BookStack\Http\ApiController;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
@ -63,4 +64,15 @@ class PageExportApiController extends ApiController
|
|||||||
|
|
||||||
return $this->download()->directly($markdown, $page->slug . '.md');
|
return $this->download()->directly($markdown, $page->slug . '.md');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
public function exportZip(int $id, ZipExportBuilder $builder)
|
||||||
|
{
|
||||||
|
$page = $this->queries->findVisibleByIdOrFail($id);
|
||||||
|
$pageSlug = $page->slug;
|
||||||
|
$zip = $builder->buildForPage($page);
|
||||||
|
|
||||||
|
return $this->download()->streamedFileDirectly($zip, $pageSlug . '.zip', filesize($zip), true);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user