Add mutation to clear the cached images (#775)

This commit is contained in:
schroda
2023-11-25 17:53:29 +01:00
committed by GitHub
parent 9110c07ed9
commit d21b2018cb
3 changed files with 63 additions and 0 deletions
@@ -0,0 +1,57 @@
package suwayomi.tachidesk.graphql.mutations
import org.kodein.di.DI
import org.kodein.di.conf.global
import org.kodein.di.instance
import suwayomi.tachidesk.manga.impl.util.storage.ImageResponse
import suwayomi.tachidesk.server.ApplicationDirs
private val applicationDirs by DI.global.instance<ApplicationDirs>()
class ImageMutation {
data class ClearCachedImagesInput(
val clientMutationId: String? = null,
val downloadedThumbnails: Boolean? = null,
val cachedThumbnails: Boolean? = null,
val cachedPages: Boolean? = null,
)
data class ClearCachedImagesPayload(
val clientMutationId: String? = null,
val downloadedThumbnails: Boolean?,
val cachedThumbnails: Boolean?,
val cachedPages: Boolean?,
)
fun clearCachedImages(input: ClearCachedImagesInput): ClearCachedImagesPayload {
val (clientMutationId, downloadedThumbnails, cachedThumbnails, cachedPages) = input
val downloadedThumbnailsResult =
if (downloadedThumbnails == true) {
ImageResponse.clearImages(applicationDirs.thumbnailDownloadsRoot)
} else {
null
}
val cachedThumbnailsResult =
if (cachedThumbnails == true) {
ImageResponse.clearImages(applicationDirs.tempThumbnailCacheRoot)
} else {
null
}
val cachedPagesResult =
if (cachedPages == true) {
ImageResponse.clearImages(applicationDirs.tempMangaCacheRoot)
} else {
null
}
return ClearCachedImagesPayload(
clientMutationId,
downloadedThumbnails = downloadedThumbnailsResult,
cachedThumbnails = cachedThumbnailsResult,
cachedPages = cachedPagesResult,
)
}
}
@@ -18,6 +18,7 @@ import suwayomi.tachidesk.graphql.mutations.CategoryMutation
import suwayomi.tachidesk.graphql.mutations.ChapterMutation
import suwayomi.tachidesk.graphql.mutations.DownloadMutation
import suwayomi.tachidesk.graphql.mutations.ExtensionMutation
import suwayomi.tachidesk.graphql.mutations.ImageMutation
import suwayomi.tachidesk.graphql.mutations.InfoMutation
import suwayomi.tachidesk.graphql.mutations.MangaMutation
import suwayomi.tachidesk.graphql.mutations.MetaMutation
@@ -84,6 +85,7 @@ val schema =
TopLevelObject(ChapterMutation()),
TopLevelObject(DownloadMutation()),
TopLevelObject(ExtensionMutation()),
TopLevelObject(ImageMutation()),
TopLevelObject(InfoMutation()),
TopLevelObject(MangaMutation()),
TopLevelObject(MetaMutation()),
@@ -114,4 +114,8 @@ object ImageResponse {
File(it).delete()
}
}
fun clearImages(saveDir: String): Boolean {
return File(saveDir).deleteRecursively()
}
}