Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mutation to clear the cached images #775

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}