mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-04 11:24:35 -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.selectAll
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
import org.jetbrains.exposed.sql.update
|
import org.jetbrains.exposed.sql.update
|
||||||
|
import suwayomi.tachidesk.graphql.types.StartSyncResult
|
||||||
import suwayomi.tachidesk.manga.impl.Category
|
import suwayomi.tachidesk.manga.impl.Category
|
||||||
import suwayomi.tachidesk.manga.impl.backup.BackupFlags
|
import suwayomi.tachidesk.manga.impl.backup.BackupFlags
|
||||||
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupImport
|
import suwayomi.tachidesk.manga.impl.backup.proto.ProtoBackupImport
|
||||||
@@ -80,13 +81,13 @@ object SyncManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(DelicateCoroutinesApi::class)
|
@OptIn(DelicateCoroutinesApi::class)
|
||||||
fun startSync() {
|
fun startSync(): StartSyncResult {
|
||||||
if (!serverConfig.syncYomiEnabled.value) {
|
if (!serverConfig.syncYomiEnabled.value) {
|
||||||
return
|
return StartSyncResult.SYNC_DISABLED
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!syncMutex.tryLock()) {
|
if (!syncMutex.tryLock()) {
|
||||||
return
|
return StartSyncResult.SYNC_IN_PROGRESS
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
@@ -94,6 +95,8 @@ object SyncManager {
|
|||||||
}.invokeOnCompletion {
|
}.invokeOnCompletion {
|
||||||
syncMutex.unlock()
|
syncMutex.unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return StartSyncResult.SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun syncData() {
|
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.global.impl.sync.SyncManager
|
||||||
import suwayomi.tachidesk.graphql.directives.RequireAuth
|
import suwayomi.tachidesk.graphql.directives.RequireAuth
|
||||||
|
import suwayomi.tachidesk.graphql.types.StartSyncResult
|
||||||
|
|
||||||
class SyncMutation {
|
class SyncMutation {
|
||||||
data class StartSyncInput(
|
data class StartSyncInput(
|
||||||
@@ -10,16 +11,18 @@ class SyncMutation {
|
|||||||
|
|
||||||
data class StartSyncPayload(
|
data class StartSyncPayload(
|
||||||
val clientMutationId: String? = null,
|
val clientMutationId: String? = null,
|
||||||
|
val result: StartSyncResult,
|
||||||
)
|
)
|
||||||
|
|
||||||
@RequireAuth
|
@RequireAuth
|
||||||
fun startSync(input: StartSyncInput): StartSyncPayload {
|
fun startSync(input: StartSyncInput): StartSyncPayload {
|
||||||
val (clientMutationId) = input
|
val (clientMutationId) = input
|
||||||
|
|
||||||
SyncManager.startSync()
|
val result = SyncManager.startSync()
|
||||||
|
|
||||||
return StartSyncPayload(
|
return StartSyncPayload(
|
||||||
clientMutationId = clientMutationId,
|
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