mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-03 10:54:38 -05:00
Add mutation to clear the cached images (#775)
This commit is contained in:
@@ -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.ChapterMutation
|
||||||
import suwayomi.tachidesk.graphql.mutations.DownloadMutation
|
import suwayomi.tachidesk.graphql.mutations.DownloadMutation
|
||||||
import suwayomi.tachidesk.graphql.mutations.ExtensionMutation
|
import suwayomi.tachidesk.graphql.mutations.ExtensionMutation
|
||||||
|
import suwayomi.tachidesk.graphql.mutations.ImageMutation
|
||||||
import suwayomi.tachidesk.graphql.mutations.InfoMutation
|
import suwayomi.tachidesk.graphql.mutations.InfoMutation
|
||||||
import suwayomi.tachidesk.graphql.mutations.MangaMutation
|
import suwayomi.tachidesk.graphql.mutations.MangaMutation
|
||||||
import suwayomi.tachidesk.graphql.mutations.MetaMutation
|
import suwayomi.tachidesk.graphql.mutations.MetaMutation
|
||||||
@@ -84,6 +85,7 @@ val schema =
|
|||||||
TopLevelObject(ChapterMutation()),
|
TopLevelObject(ChapterMutation()),
|
||||||
TopLevelObject(DownloadMutation()),
|
TopLevelObject(DownloadMutation()),
|
||||||
TopLevelObject(ExtensionMutation()),
|
TopLevelObject(ExtensionMutation()),
|
||||||
|
TopLevelObject(ImageMutation()),
|
||||||
TopLevelObject(InfoMutation()),
|
TopLevelObject(InfoMutation()),
|
||||||
TopLevelObject(MangaMutation()),
|
TopLevelObject(MangaMutation()),
|
||||||
TopLevelObject(MetaMutation()),
|
TopLevelObject(MetaMutation()),
|
||||||
|
|||||||
@@ -114,4 +114,8 @@ object ImageResponse {
|
|||||||
File(it).delete()
|
File(it).delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun clearImages(saveDir: String): Boolean {
|
||||||
|
return File(saveDir).deleteRecursively()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user