This commit is contained in:
Horis 2024-03-13 21:45:08 +08:00
parent d5a581f75b
commit 005839257f

View File

@ -64,6 +64,7 @@ import me.ag2s.epublib.domain.FileResourceProvider
import me.ag2s.epublib.domain.LazyResource import me.ag2s.epublib.domain.LazyResource
import me.ag2s.epublib.domain.Metadata import me.ag2s.epublib.domain.Metadata
import me.ag2s.epublib.domain.Resource import me.ag2s.epublib.domain.Resource
import me.ag2s.epublib.domain.TOCReference
import me.ag2s.epublib.epub.EpubWriter import me.ag2s.epublib.epub.EpubWriter
import me.ag2s.epublib.epub.EpubWriterProcessor import me.ag2s.epublib.epub.EpubWriterProcessor
import me.ag2s.epublib.util.ResourceUtil import me.ag2s.epublib.util.ResourceUtil
@ -630,6 +631,7 @@ class ExportBookService : BaseService() {
} else { } else {
1 1
} }
var parentSection: TOCReference? = null
flow { flow {
appDb.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter -> appDb.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter ->
emit(chapter) emit(chapter)
@ -667,19 +669,27 @@ class ExportBookService : BaseService() {
contentModel, contentModel,
"Text/chapter_${index}.html" "Text/chapter_${index}.html"
) )
ExportChapter(title, chapterResource, resources) ExportChapter(title, chapterResource, resources, chapter)
}.collectIndexed { index, exportChapter -> }.collectIndexed { index, exportChapter ->
postEvent(EventBus.EXPORT_BOOK, book.bookUrl) postEvent(EventBus.EXPORT_BOOK, book.bookUrl)
exportProgress[book.bookUrl] = index exportProgress[book.bookUrl] = index
epubBook.resources.addAll(exportChapter.resources) val (title, chapterResource, resources, chapter) = exportChapter
epubBook.addSection(exportChapter.title, exportChapter.chapterResource) epubBook.resources.addAll(resources)
if (chapter.isVolume) {
parentSection = epubBook.addSection(title, chapterResource)
} else if (parentSection == null) {
epubBook.addSection(title, chapterResource)
} else {
epubBook.addSection(parentSection, title, chapterResource)
}
} }
} }
data class ExportChapter( data class ExportChapter(
val title: String, val title: String,
val chapterResource: Resource, val chapterResource: Resource,
val resources: ArrayList<Resource> val resources: ArrayList<Resource>,
val chapter: BookChapter
) )
private fun fixPic( private fun fixPic(