mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 03:14:40 -05:00
* Update exposed to v1 * Update Exposed * Add Kotlinx.DateTime extensions * Update H2 * Review comments --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Syer10 <syer10@users.noreply.github.com>
124 lines
3.6 KiB
Kotlin
124 lines
3.6 KiB
Kotlin
@file:Suppress("RedundantNullableReturnType", "unused")
|
|
|
|
package suwayomi.tachidesk.graphql.mutations
|
|
|
|
import kotlinx.coroutines.flow.first
|
|
import kotlinx.coroutines.withTimeout
|
|
import suwayomi.tachidesk.graphql.directives.RequireAuth
|
|
import suwayomi.tachidesk.graphql.types.LibraryUpdateStatus
|
|
import suwayomi.tachidesk.graphql.types.UpdateStatus
|
|
import suwayomi.tachidesk.manga.impl.Category
|
|
import suwayomi.tachidesk.manga.impl.update.IUpdater
|
|
import suwayomi.tachidesk.server.JavalinSetup.future
|
|
import uy.kohesive.injekt.injectLazy
|
|
import java.util.concurrent.CompletableFuture
|
|
import kotlin.time.Duration.Companion.seconds
|
|
|
|
class UpdateMutation {
|
|
private val updater: IUpdater by injectLazy()
|
|
|
|
data class UpdateLibraryInput(
|
|
val clientMutationId: String? = null,
|
|
val categories: List<Int>?,
|
|
)
|
|
|
|
data class UpdateLibraryPayload(
|
|
val clientMutationId: String? = null,
|
|
val updateStatus: LibraryUpdateStatus,
|
|
)
|
|
|
|
@RequireAuth
|
|
fun updateLibrary(input: UpdateLibraryInput): CompletableFuture<UpdateLibraryPayload?> {
|
|
updater.addCategoriesToUpdateQueue(
|
|
Category.getCategoryList().filter { input.categories?.contains(it.id) ?: true },
|
|
clear = true,
|
|
forceAll = !input.categories.isNullOrEmpty(),
|
|
)
|
|
|
|
return future {
|
|
UpdateLibraryPayload(
|
|
input.clientMutationId,
|
|
updateStatus =
|
|
withTimeout(30.seconds) {
|
|
LibraryUpdateStatus(
|
|
updater.updates.first(),
|
|
)
|
|
},
|
|
)
|
|
}
|
|
}
|
|
|
|
data class UpdateLibraryMangaInput(
|
|
val clientMutationId: String? = null,
|
|
)
|
|
|
|
data class UpdateLibraryMangaPayload(
|
|
val clientMutationId: String?,
|
|
val updateStatus: UpdateStatus,
|
|
)
|
|
|
|
@RequireAuth
|
|
fun updateLibraryManga(input: UpdateLibraryMangaInput): CompletableFuture<UpdateLibraryMangaPayload?> {
|
|
updateLibrary(
|
|
UpdateLibraryInput(
|
|
clientMutationId = input.clientMutationId,
|
|
categories = null,
|
|
),
|
|
)
|
|
|
|
return future {
|
|
UpdateLibraryMangaPayload(
|
|
input.clientMutationId,
|
|
updateStatus =
|
|
withTimeout(30.seconds) {
|
|
UpdateStatus(updater.status.first())
|
|
},
|
|
)
|
|
}
|
|
}
|
|
|
|
data class UpdateCategoryMangaInput(
|
|
val clientMutationId: String? = null,
|
|
val categories: List<Int>,
|
|
)
|
|
|
|
data class UpdateCategoryMangaPayload(
|
|
val clientMutationId: String?,
|
|
val updateStatus: UpdateStatus,
|
|
)
|
|
|
|
@RequireAuth
|
|
fun updateCategoryManga(input: UpdateCategoryMangaInput): CompletableFuture<UpdateCategoryMangaPayload?> {
|
|
updateLibrary(
|
|
UpdateLibraryInput(
|
|
clientMutationId = input.clientMutationId,
|
|
categories = input.categories,
|
|
),
|
|
)
|
|
|
|
return future {
|
|
UpdateCategoryMangaPayload(
|
|
input.clientMutationId,
|
|
updateStatus =
|
|
withTimeout(30.seconds) {
|
|
UpdateStatus(updater.status.first())
|
|
},
|
|
)
|
|
}
|
|
}
|
|
|
|
data class UpdateStopInput(
|
|
val clientMutationId: String? = null,
|
|
)
|
|
|
|
data class UpdateStopPayload(
|
|
val clientMutationId: String?,
|
|
)
|
|
|
|
@RequireAuth
|
|
fun updateStop(input: UpdateStopInput): UpdateStopPayload {
|
|
updater.reset()
|
|
return UpdateStopPayload(input.clientMutationId)
|
|
}
|
|
}
|