Skip to content

Commit

Permalink
Add mutation to clear the cached images (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
schroda authored Nov 25, 2023
1 parent 9110c07 commit d21b201
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,6 +85,7 @@ val schema =
TopLevelObject(ChapterMutation()),
TopLevelObject(DownloadMutation()),
TopLevelObject(ExtensionMutation()),
TopLevelObject(ImageMutation()),
TopLevelObject(InfoMutation()),
TopLevelObject(MangaMutation()),
TopLevelObject(MetaMutation()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,8 @@ object ImageResponse {
File(it).delete()
}
}

fun clearImages(saveDir: String): Boolean {
return File(saveDir).deleteRecursively()
}
}

0 comments on commit d21b201

Please sign in to comment.