Skip to content

Commit

Permalink
Automatic merge branch 'current-stable' into 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Auto CI committed Nov 4, 2023
2 parents 791033f + 8263786 commit 6334da1
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ import java.net.URLDecoder
import java.util.zip.GZIPOutputStream

private val urlRe = Regex("""^https?://.*""")

const val EPUB_OPTIMIZER_VERSION = 2

fun EpubBackendState.readOriginal(origId: String): Pair<Document?, Int> {
val file = fileForOriginalId(origId)?: return Pair(null, 0)
val parentFolder = file.parentFile!!
Expand Down Expand Up @@ -232,7 +235,9 @@ fun EpubBackendState.optimizeEpub() {
val (origDocument, maxOrdinal) = readOriginal(k)
origDocument ?: continue

val fragments = splitIntoFragments(k, origDocument, maxOrdinal)
val fragments = splitIntoFragments(k, origDocument, maxOrdinal).let {
it.ifEmpty{ listOf(EpubFragment(k, 0, 0).apply { element = origDocument.rootElement }) }
}
val ids = writeDao.insert(*fragments.toTypedArray())
for((id, frag) in ids.zip(fragments)) {
frag.id = id
Expand All @@ -257,6 +262,10 @@ fun EpubBackendState.optimizeEpub() {
}
fileForOriginalId(k)?.delete()
}
val versionFile = File(fragDir, "version.txt")
versionFile.outputStream().use {
it.write("$EPUB_OPTIMIZER_VERSION".toByteArray())
}
val total = (System.currentTimeMillis() - start) / 1000
writeDb.close()
optimizeLockFile.delete()
Expand Down

0 comments on commit 6334da1

Please sign in to comment.