mirror of
https://github.com/gotson/komga.git
synced 2026-05-06 03:27:08 +02:00
parent
c0c7b09faa
commit
57082bd990
1 changed files with 4 additions and 12 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
package org.gotson.komga.infrastructure.mediacontainer
|
package org.gotson.komga.infrastructure.mediacontainer
|
||||||
|
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine
|
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator
|
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator
|
||||||
import org.apache.commons.compress.archivers.ArchiveEntry
|
import org.apache.commons.compress.archivers.ArchiveEntry
|
||||||
|
|
@ -10,7 +9,6 @@ import org.gotson.komga.domain.model.MediaType
|
||||||
import org.gotson.komga.infrastructure.image.ImageAnalyzer
|
import org.gotson.komga.infrastructure.image.ImageAnalyzer
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
private val logger = KotlinLogging.logger {}
|
private val logger = KotlinLogging.logger {}
|
||||||
|
|
||||||
|
|
@ -20,12 +18,6 @@ class ZipExtractor(
|
||||||
private val imageAnalyzer: ImageAnalyzer,
|
private val imageAnalyzer: ImageAnalyzer,
|
||||||
) : MediaContainerExtractor {
|
) : MediaContainerExtractor {
|
||||||
|
|
||||||
private val cache = Caffeine.newBuilder()
|
|
||||||
.maximumSize(20)
|
|
||||||
.expireAfterAccess(1, TimeUnit.MINUTES)
|
|
||||||
.evictionListener { _: Path?, zip: ZipFile?, _ -> zip?.close() }
|
|
||||||
.build<Path, ZipFile>()
|
|
||||||
|
|
||||||
private val natSortComparator: Comparator<String> = CaseInsensitiveSimpleNaturalComparator.getInstance()
|
private val natSortComparator: Comparator<String> = CaseInsensitiveSimpleNaturalComparator.getInstance()
|
||||||
|
|
||||||
override fun mediaTypes(): List<String> = listOf(MediaType.ZIP.value)
|
override fun mediaTypes(): List<String> = listOf(MediaType.ZIP.value)
|
||||||
|
|
@ -53,8 +45,8 @@ class ZipExtractor(
|
||||||
.sortedWith(compareBy(natSortComparator) { it.name })
|
.sortedWith(compareBy(natSortComparator) { it.name })
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getEntryStream(path: Path, entryName: String): ByteArray {
|
override fun getEntryStream(path: Path, entryName: String): ByteArray =
|
||||||
val zip = cache.get(path) { ZipFile(path.toFile()) }!!
|
ZipFile(path.toFile()).use { zip ->
|
||||||
return zip.getInputStream(zip.getEntry(entryName)).use { it.readBytes() }
|
zip.getInputStream(zip.getEntry(entryName)).use { it.readBytes() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue