-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mutation to clear the cached images (#775)
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/ImageMutation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters