mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-06-30 17:34:39 -05:00
use commons-compress everywhere (#570)
This commit is contained in:
@@ -26,6 +26,7 @@ import kotlinx.serialization.json.intOrNull
|
|||||||
import kotlinx.serialization.json.jsonArray
|
import kotlinx.serialization.json.jsonArray
|
||||||
import kotlinx.serialization.json.jsonPrimitive
|
import kotlinx.serialization.json.jsonPrimitive
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
|
import org.apache.commons.compress.archivers.zip.ZipFile
|
||||||
import org.jetbrains.exposed.sql.insert
|
import org.jetbrains.exposed.sql.insert
|
||||||
import org.jetbrains.exposed.sql.insertAndGetId
|
import org.jetbrains.exposed.sql.insertAndGetId
|
||||||
import org.jetbrains.exposed.sql.select
|
import org.jetbrains.exposed.sql.select
|
||||||
@@ -45,7 +46,6 @@ import java.io.FileInputStream
|
|||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import java.util.zip.ZipFile
|
|
||||||
|
|
||||||
class LocalSource : CatalogueSource {
|
class LocalSource : CatalogueSource {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -356,7 +356,7 @@ class LocalSource : CatalogueSource {
|
|||||||
}
|
}
|
||||||
is Format.Zip -> {
|
is Format.Zip -> {
|
||||||
ZipFile(format.file).use { zip ->
|
ZipFile(format.file).use { zip ->
|
||||||
val entry = zip.entries().toList()
|
val entry = zip.entries.toList()
|
||||||
.sortedWith { f1, f2 -> f1.name.compareToCaseInsensitiveNaturalOrder(f2.name) }
|
.sortedWith { f1, f2 -> f1.name.compareToCaseInsensitiveNaturalOrder(f2.name) }
|
||||||
.find { !it.isDirectory && ImageUtil.isImage(it.name) { zip.getInputStream(it) } }
|
.find { !it.isDirectory && ImageUtil.isImage(it.name) { zip.getInputStream(it) } }
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package eu.kanade.tachiyomi.source.local.loader
|
package eu.kanade.tachiyomi.source.local.loader
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder
|
import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder
|
||||||
|
import org.apache.commons.compress.archivers.zip.ZipFile
|
||||||
import suwayomi.tachidesk.manga.impl.util.storage.ImageUtil
|
import suwayomi.tachidesk.manga.impl.util.storage.ImageUtil
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import org.apache.commons.compress.archivers.zip.ZipFile
|
|
||||||
|
|
||||||
class ZipPageLoader(file: File) : PageLoader {
|
class ZipPageLoader(file: File) : PageLoader {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package eu.kanade.tachiyomi.util.storage
|
|||||||
|
|
||||||
import eu.kanade.tachiyomi.source.model.SChapter
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
|
||||||
|
import org.apache.commons.compress.archivers.zip.ZipFile
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
import org.jsoup.nodes.Document
|
import org.jsoup.nodes.Document
|
||||||
import java.io.Closeable
|
import java.io.Closeable
|
||||||
@@ -10,8 +12,6 @@ import java.io.InputStream
|
|||||||
import java.text.ParseException
|
import java.text.ParseException
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import java.util.zip.ZipEntry
|
|
||||||
import java.util.zip.ZipFile
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper over ZipFile to load files in epub format.
|
* Wrapper over ZipFile to load files in epub format.
|
||||||
@@ -38,14 +38,14 @@ class EpubFile(file: File) : Closeable {
|
|||||||
/**
|
/**
|
||||||
* Returns an input stream for reading the contents of the specified zip file entry.
|
* Returns an input stream for reading the contents of the specified zip file entry.
|
||||||
*/
|
*/
|
||||||
fun getInputStream(entry: ZipEntry): InputStream {
|
fun getInputStream(entry: ZipArchiveEntry): InputStream {
|
||||||
return zip.getInputStream(entry)
|
return zip.getInputStream(entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the zip file entry for the specified name, or null if not found.
|
* Returns the zip file entry for the specified name, or null if not found.
|
||||||
*/
|
*/
|
||||||
fun getEntry(name: String): ZipEntry? {
|
fun getEntry(name: String): ZipArchiveEntry? {
|
||||||
return zip.getEntry(name)
|
return zip.getEntry(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import org.jetbrains.exposed.sql.select
|
|||||||
import org.jetbrains.exposed.sql.selectAll
|
import org.jetbrains.exposed.sql.selectAll
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
import org.jetbrains.exposed.sql.update
|
import org.jetbrains.exposed.sql.update
|
||||||
import suwayomi.tachidesk.manga.impl.CategoryManga.removeMangaFromCategory
|
|
||||||
import suwayomi.tachidesk.manga.model.dataclass.CategoryDataClass
|
import suwayomi.tachidesk.manga.model.dataclass.CategoryDataClass
|
||||||
import suwayomi.tachidesk.manga.model.table.CategoryMangaTable
|
import suwayomi.tachidesk.manga.model.table.CategoryMangaTable
|
||||||
import suwayomi.tachidesk.manga.model.table.CategoryMetaTable
|
import suwayomi.tachidesk.manga.model.table.CategoryMetaTable
|
||||||
|
|||||||
@@ -3,21 +3,21 @@ package suwayomi.tachidesk.manga.impl.download
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
|
||||||
|
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream
|
||||||
|
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
|
||||||
|
import org.apache.commons.compress.archivers.zip.ZipFile
|
||||||
import suwayomi.tachidesk.manga.impl.download.model.DownloadChapter
|
import suwayomi.tachidesk.manga.impl.download.model.DownloadChapter
|
||||||
import suwayomi.tachidesk.manga.impl.util.getChapterCbzPath
|
import suwayomi.tachidesk.manga.impl.util.getChapterCbzPath
|
||||||
import suwayomi.tachidesk.manga.impl.util.getChapterDownloadPath
|
import suwayomi.tachidesk.manga.impl.util.getChapterDownloadPath
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.util.zip.ZipEntry
|
|
||||||
import java.util.zip.ZipFile
|
|
||||||
import java.util.zip.ZipInputStream
|
|
||||||
import java.util.zip.ZipOutputStream
|
|
||||||
|
|
||||||
class ArchiveProvider(mangaId: Int, chapterId: Int) : DownloadedFilesProvider(mangaId, chapterId) {
|
class ArchiveProvider(mangaId: Int, chapterId: Int) : DownloadedFilesProvider(mangaId, chapterId) {
|
||||||
override fun getImage(index: Int): Pair<InputStream, String> {
|
override fun getImage(index: Int): Pair<InputStream, String> {
|
||||||
val cbzPath = getChapterCbzPath(mangaId, chapterId)
|
val cbzPath = getChapterCbzPath(mangaId, chapterId)
|
||||||
val zipFile = ZipFile(cbzPath)
|
val zipFile = ZipFile(cbzPath)
|
||||||
val zipEntry = zipFile.entries().toList().sortedWith(compareBy({ it.name }, { it.name }))[index]
|
val zipEntry = zipFile.entries.toList().sortedWith(compareBy({ it.name }, { it.name }))[index]
|
||||||
val inputStream = zipFile.getInputStream(zipEntry)
|
val inputStream = zipFile.getInputStream(zipEntry)
|
||||||
val fileType = zipEntry.name.substringAfterLast(".")
|
val fileType = zipEntry.name.substringAfterLast(".")
|
||||||
return Pair(inputStream.buffered(), "image/$fileType")
|
return Pair(inputStream.buffered(), "image/$fileType")
|
||||||
@@ -39,17 +39,17 @@ class ArchiveProvider(mangaId: Int, chapterId: Int) : DownloadedFilesProvider(ma
|
|||||||
outputFile.createNewFile()
|
outputFile.createNewFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
ZipOutputStream(outputFile.outputStream()).use { zipOut ->
|
ZipArchiveOutputStream(outputFile.outputStream()).use { zipOut ->
|
||||||
if (chapterFolder.isDirectory) {
|
if (chapterFolder.isDirectory) {
|
||||||
chapterFolder.listFiles()?.sortedBy { it.name }?.forEach {
|
chapterFolder.listFiles()?.sortedBy { it.name }?.forEach {
|
||||||
val entry = ZipEntry(it.name)
|
val entry = ZipArchiveEntry(it.name)
|
||||||
try {
|
try {
|
||||||
zipOut.putNextEntry(entry)
|
zipOut.putArchiveEntry(entry)
|
||||||
it.inputStream().use { inputStream ->
|
it.inputStream().use { inputStream ->
|
||||||
inputStream.copyTo(zipOut)
|
inputStream.copyTo(zipOut)
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
zipOut.closeEntry()
|
zipOut.closeArchiveEntry()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ class ArchiveProvider(mangaId: Int, chapterId: Int) : DownloadedFilesProvider(ma
|
|||||||
|
|
||||||
private fun handleExistingCbzFile(cbzFile: File, chapterFolder: File) {
|
private fun handleExistingCbzFile(cbzFile: File, chapterFolder: File) {
|
||||||
if (!chapterFolder.exists()) chapterFolder.mkdirs()
|
if (!chapterFolder.exists()) chapterFolder.mkdirs()
|
||||||
ZipInputStream(cbzFile.inputStream()).use { zipInputStream ->
|
ZipArchiveInputStream(cbzFile.inputStream()).use { zipInputStream ->
|
||||||
var zipEntry = zipInputStream.nextEntry
|
var zipEntry = zipInputStream.nextEntry
|
||||||
while (zipEntry != null) {
|
while (zipEntry != null) {
|
||||||
val file = File(chapterFolder, zipEntry.name)
|
val file = File(chapterFolder, zipEntry.name)
|
||||||
|
|||||||
Reference in New Issue
Block a user