mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-11 23:04:33 -05:00
Feature/decouple thumbnail downloads and cache (#581)
* Rename "DownloadedFilesProvider" to "ChaptersFilesProvider" * Move files into sub packages * Further abstract "DownloadedFilesProvider" * Rename "getCachedImageResponse" to "getImageResponse" * Extract getting cached image response into new function * Decouple thumbnail cache and download * Download and delete permanent thumbnails When adding/removing manga from/to the library make sure the permanent thumbnail files will get handled properly * Move thumbnail cache to actual temp folder * Rename "mangaDownloadsRoot" to "downloadRoot" * Move manga downloads into "mangas" subfolder * Clear downloaded thumbnail
This commit is contained in:
@@ -44,6 +44,10 @@ private fun getChapterDir(mangaId: Int, chapterId: Int): String {
|
||||
return getMangaDir(mangaId) + "/$chapterDir"
|
||||
}
|
||||
|
||||
fun getThumbnailDownloadPath(mangaId: Int): String {
|
||||
return applicationDirs.thumbnailDownloadsRoot + "/$mangaId"
|
||||
}
|
||||
|
||||
fun getChapterDownloadPath(mangaId: Int, chapterId: Int): String {
|
||||
return applicationDirs.mangaDownloadsRoot + "/" + getChapterDir(mangaId, chapterId)
|
||||
}
|
||||
@@ -66,8 +70,8 @@ fun updateMangaDownloadDir(mangaId: Int, newTitle: String): Boolean {
|
||||
|
||||
val newMangaDir = SafePath.buildValidFilename(newTitle)
|
||||
|
||||
val oldDir = "${applicationDirs.mangaDownloadsRoot}/$sourceDir/$mangaDir"
|
||||
val newDir = "${applicationDirs.mangaDownloadsRoot}/$sourceDir/$newMangaDir"
|
||||
val oldDir = "${applicationDirs.downloadsRoot}/$sourceDir/$mangaDir"
|
||||
val newDir = "${applicationDirs.downloadsRoot}/$sourceDir/$newMangaDir"
|
||||
|
||||
val oldDirFile = File(oldDir)
|
||||
val newDirFile = File(newDir)
|
||||
|
||||
@@ -30,6 +30,14 @@ object ImageResponse {
|
||||
return null
|
||||
}
|
||||
|
||||
fun getCachedImageResponse(cachedFile: String, filePath: String): Pair<InputStream, String> {
|
||||
val fileType = cachedFile.substringAfter("$filePath.")
|
||||
return Pair(
|
||||
pathToInputStream(cachedFile),
|
||||
"image/$fileType"
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a cached image response
|
||||
*
|
||||
@@ -38,7 +46,7 @@ object ImageResponse {
|
||||
* @param cacheSavePath where to save the cached image. Caller should decide to use perma cache or temp cache (OS temp dir)
|
||||
* @param fileName what the saved cache file should be named
|
||||
*/
|
||||
suspend fun getCachedImageResponse(
|
||||
suspend fun getImageResponse(
|
||||
saveDir: String,
|
||||
fileName: String,
|
||||
fetcher: suspend () -> Response
|
||||
@@ -50,11 +58,7 @@ object ImageResponse {
|
||||
|
||||
// in case the cached file is a ".tmp" file something went wrong with the previous download, and it has to be downloaded again
|
||||
if (cachedFile != null && !cachedFile.endsWith(".tmp")) {
|
||||
val fileType = cachedFile.substringAfter("$filePath.")
|
||||
return Pair(
|
||||
pathToInputStream(cachedFile),
|
||||
"image/$fileType"
|
||||
)
|
||||
return getCachedImageResponse(cachedFile, filePath)
|
||||
}
|
||||
|
||||
val response = fetcher()
|
||||
|
||||
Reference in New Issue
Block a user