Merge branch 'sync-part-final' into feat/add-sync-triggers-experimental

This commit is contained in:
KaiserBh 2024-01-04 22:15:04 +11:00
commit c6a147bc84
No known key found for this signature in database
GPG Key ID: 14D73B142042BBA9
3 changed files with 9 additions and 9 deletions

View File

@ -61,7 +61,7 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
override suspend fun beforeSync() = googleDriveService.refreshToken() override suspend fun beforeSync() = googleDriveService.refreshToken()
override suspend fun pushSyncData(): SyncData? { override suspend fun pullSyncData(): SyncData? {
val drive = googleDriveService.googleDriveService val drive = googleDriveService.googleDriveService
// Check if the Google Drive service is initialized // Check if the Google Drive service is initialized
@ -87,7 +87,7 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
return json.decodeFromString(SyncData.serializer(), jsonString) return json.decodeFromString(SyncData.serializer(), jsonString)
} }
override suspend fun pullSyncData(syncData: SyncData) { override suspend fun pushSyncData(syncData: SyncData) {
val jsonData = json.encodeToString(syncData) val jsonData = json.encodeToString(syncData)
val drive = googleDriveService.googleDriveService val drive = googleDriveService.googleDriveService

View File

@ -23,15 +23,15 @@ abstract class SyncService(
open suspend fun doSync(syncData: SyncData): Backup? { open suspend fun doSync(syncData: SyncData): Backup? {
beforeSync() beforeSync()
val remoteSData = pushSyncData() val remoteSData = pullSyncData()
val finalSyncData = val finalSyncData =
if (remoteSData == null) { if (remoteSData == null) {
pullSyncData(syncData) pushSyncData(syncData)
syncData syncData
} else { } else {
val mergedSyncData = mergeSyncData(syncData, remoteSData) val mergedSyncData = mergeSyncData(syncData, remoteSData)
pullSyncData(mergedSyncData) pushSyncData(mergedSyncData)
mergedSyncData mergedSyncData
} }
@ -46,12 +46,12 @@ abstract class SyncService(
/** /**
* Download sync data from the remote storage * Download sync data from the remote storage
*/ */
abstract suspend fun pushSyncData(): SyncData? abstract suspend fun pullSyncData(): SyncData?
/** /**
* Upload sync data to the remote storage * Upload sync data to the remote storage
*/ */
abstract suspend fun pullSyncData(syncData: SyncData) abstract suspend fun pushSyncData(syncData: SyncData)
/** /**
* Merges the local and remote sync data into a single JSON string. * Merges the local and remote sync data into a single JSON string.

View File

@ -22,7 +22,7 @@ class SyncYomiSyncService(
syncPreferences: SyncPreferences, syncPreferences: SyncPreferences,
private val notifier: SyncNotifier, private val notifier: SyncNotifier,
) : SyncService(context, json, syncPreferences) { ) : SyncService(context, json, syncPreferences) {
override suspend fun pushSyncData(): SyncData? { override suspend fun pullSyncData(): SyncData? {
val host = syncPreferences.syncHost().get() val host = syncPreferences.syncHost().get()
val apiKey = syncPreferences.syncAPIKey().get() val apiKey = syncPreferences.syncAPIKey().get()
val downloadUrl = "$host/api/sync/download" val downloadUrl = "$host/api/sync/download"
@ -48,7 +48,7 @@ class SyncYomiSyncService(
} }
} }
override suspend fun pullSyncData(syncData: SyncData) { override suspend fun pushSyncData(syncData: SyncData) {
val host = syncPreferences.syncHost().get() val host = syncPreferences.syncHost().get()
val apiKey = syncPreferences.syncAPIKey().get() val apiKey = syncPreferences.syncAPIKey().get()
val uploadUrl = "$host/api/sync/upload" val uploadUrl = "$host/api/sync/upload"