mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-12 23:34:34 -05:00
Decouple Cache and Download behaviour (#493)
* Separate cache dir from download dir * Move downloader logic outside of caching/image download logic * remove unnecessary method duplication * moved download logic inside download provider * optimize and handle partial downloads * made code review changes
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package suwayomi.tachidesk.manga.impl
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import suwayomi.tachidesk.manga.impl.download.DownloadedFilesProvider
|
||||
import suwayomi.tachidesk.manga.impl.download.FolderProvider
|
||||
import suwayomi.tachidesk.manga.impl.download.model.DownloadChapter
|
||||
import java.io.InputStream
|
||||
|
||||
object ChapterDownloadHelper {
|
||||
fun getImage(mangaId: Int, chapterId: Int, index: Int): Pair<InputStream, String> {
|
||||
return provider(mangaId, chapterId).getImage(index)
|
||||
}
|
||||
|
||||
fun delete(mangaId: Int, chapterId: Int): Boolean {
|
||||
return provider(mangaId, chapterId).delete()
|
||||
}
|
||||
|
||||
suspend fun download(
|
||||
mangaId: Int,
|
||||
chapterId: Int,
|
||||
download: DownloadChapter,
|
||||
scope: CoroutineScope,
|
||||
step: suspend (DownloadChapter?, Boolean) -> Unit
|
||||
): Boolean {
|
||||
return provider(mangaId, chapterId).download(download, scope, step)
|
||||
}
|
||||
|
||||
// return the appropriate provider based on how the download was saved. For the logic is simple but will evolve when new types of downloads are available
|
||||
private fun provider(mangaId: Int, chapterId: Int): DownloadedFilesProvider {
|
||||
return FolderProvider(mangaId, chapterId)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user