mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-02 02:14:36 -05:00
Return a result from startSync
This commit is contained in:
@@ -13,6 +13,7 @@ import kotlinx.serialization.protobuf.ProtoBuf
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.jetbrains.exposed.sql.update
|
||||
import suwayomi.tachidesk.graphql.types.StartSyncResult
|
||||
import suwayomi.tachidesk.manga.impl.Category
|
||||
import suwayomi.tachidesk.manga.impl.backup.BackupFlags
|
||||
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupImport
|
||||
@@ -80,13 +81,13 @@ object SyncManager {
|
||||
}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun startSync() {
|
||||
fun startSync(): StartSyncResult {
|
||||
if (!serverConfig.syncYomiEnabled.value) {
|
||||
return
|
||||
return StartSyncResult.SYNC_DISABLED
|
||||
}
|
||||
|
||||
if (!syncMutex.tryLock()) {
|
||||
return
|
||||
return StartSyncResult.SYNC_IN_PROGRESS
|
||||
}
|
||||
|
||||
GlobalScope.launch {
|
||||
@@ -94,6 +95,8 @@ object SyncManager {
|
||||
}.invokeOnCompletion {
|
||||
syncMutex.unlock()
|
||||
}
|
||||
|
||||
return StartSyncResult.SUCCESS
|
||||
}
|
||||
|
||||
private suspend fun syncData() {
|
||||
@@ -354,3 +357,4 @@ object SyncManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package suwayomi.tachidesk.graphql.mutations
|
||||
|
||||
import suwayomi.tachidesk.global.impl.sync.SyncManager
|
||||
import suwayomi.tachidesk.graphql.directives.RequireAuth
|
||||
import suwayomi.tachidesk.graphql.types.StartSyncResult
|
||||
|
||||
class SyncMutation {
|
||||
data class StartSyncInput(
|
||||
@@ -10,16 +11,18 @@ class SyncMutation {
|
||||
|
||||
data class StartSyncPayload(
|
||||
val clientMutationId: String? = null,
|
||||
val result: StartSyncResult,
|
||||
)
|
||||
|
||||
@RequireAuth
|
||||
fun startSync(input: StartSyncInput): StartSyncPayload {
|
||||
val (clientMutationId) = input
|
||||
|
||||
SyncManager.startSync()
|
||||
val result = SyncManager.startSync()
|
||||
|
||||
return StartSyncPayload(
|
||||
clientMutationId = clientMutationId,
|
||||
result = result,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package suwayomi.tachidesk.graphql.types
|
||||
|
||||
enum class StartSyncResult {
|
||||
SUCCESS,
|
||||
SYNC_IN_PROGRESS,
|
||||
SYNC_DISABLED,
|
||||
}
|
||||
Reference in New Issue
Block a user