mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-15 15:02:49 +01:00
chore: ktlint.
Signed-off-by: KaiserBh <kaiserbh@proton.me>
This commit is contained in:
parent
0e3c958cfe
commit
efb8d61e3e
@ -158,7 +158,9 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
|
|||||||
.setFields("id")
|
.setFields("id")
|
||||||
.execute()
|
.execute()
|
||||||
|
|
||||||
logcat(LogPriority.DEBUG) { "Created new sync data file in Google Drive with file ID: ${uploadedFile.id}" }
|
logcat(
|
||||||
|
LogPriority.DEBUG,
|
||||||
|
) { "Created new sync data file in Google Drive with file ID: ${uploadedFile.id}" }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Data has been successfully pushed or updated, delete the lock file
|
// Data has been successfully pushed or updated, delete the lock file
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package eu.kanade.tachiyomi.data.sync.service
|
package eu.kanade.tachiyomi.data.sync.service
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.google.gson.JsonObject
|
|
||||||
import eu.kanade.tachiyomi.data.sync.SyncNotifier
|
import eu.kanade.tachiyomi.data.sync.SyncNotifier
|
||||||
import eu.kanade.tachiyomi.network.GET
|
import eu.kanade.tachiyomi.network.GET
|
||||||
import eu.kanade.tachiyomi.network.PATCH
|
import eu.kanade.tachiyomi.network.PATCH
|
||||||
@ -32,10 +31,12 @@ class SyncYomiSyncService(
|
|||||||
enum class SyncStatus {
|
enum class SyncStatus {
|
||||||
@SerialName("pending")
|
@SerialName("pending")
|
||||||
Pending,
|
Pending,
|
||||||
|
|
||||||
@SerialName("syncing")
|
@SerialName("syncing")
|
||||||
Syncing,
|
Syncing,
|
||||||
|
|
||||||
@SerialName("success")
|
@SerialName("success")
|
||||||
Success
|
Success,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@ -53,7 +54,21 @@ class SyncYomiSyncService(
|
|||||||
@SerialName("acquired_at")
|
@SerialName("acquired_at")
|
||||||
val acquiredAt: String?,
|
val acquiredAt: String?,
|
||||||
@SerialName("expires_at")
|
@SerialName("expires_at")
|
||||||
val expiresAt: String?
|
val expiresAt: String?,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class LockfileCreateRequest(
|
||||||
|
@SerialName("acquired_by")
|
||||||
|
val acquiredBy: String,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class LockfilePatchRequest(
|
||||||
|
@SerialName("user_api_key")
|
||||||
|
val userApiKey: String,
|
||||||
|
@SerialName("acquired_by")
|
||||||
|
val acquiredBy: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
override suspend fun beforeSync() {
|
override suspend fun beforeSync() {
|
||||||
@ -63,13 +78,13 @@ class SyncYomiSyncService(
|
|||||||
val deviceId = syncPreferences.uniqueDeviceID()
|
val deviceId = syncPreferences.uniqueDeviceID()
|
||||||
val client = OkHttpClient()
|
val client = OkHttpClient()
|
||||||
val headers = Headers.Builder().add("X-API-Token", apiKey).build()
|
val headers = Headers.Builder().add("X-API-Token", apiKey).build()
|
||||||
val createLockfileJson = JsonObject().apply {
|
val json = Json { ignoreUnknownKeys = true }
|
||||||
addProperty("acquired_by", deviceId)
|
|
||||||
}
|
val createLockfileRequest = LockfileCreateRequest(deviceId)
|
||||||
val patchJson = JsonObject().apply {
|
val createLockfileJson = json.encodeToString(createLockfileRequest)
|
||||||
addProperty("user_api_key", apiKey)
|
|
||||||
addProperty("acquired_by", deviceId)
|
val patchRequest = LockfilePatchRequest(apiKey, deviceId)
|
||||||
}
|
val patchJson = json.encodeToString(patchRequest)
|
||||||
|
|
||||||
val lockFileRequest = GET(
|
val lockFileRequest = GET(
|
||||||
url = lockFileApi,
|
url = lockFileApi,
|
||||||
@ -79,13 +94,13 @@ class SyncYomiSyncService(
|
|||||||
val lockFileCreate = POST(
|
val lockFileCreate = POST(
|
||||||
url = lockFileApi,
|
url = lockFileApi,
|
||||||
headers = headers,
|
headers = headers,
|
||||||
body = createLockfileJson.toString().toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()),
|
body = createLockfileJson.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()),
|
||||||
)
|
)
|
||||||
|
|
||||||
val lockFileUpdate = PATCH(
|
val lockFileUpdate = PATCH(
|
||||||
url = lockFileApi,
|
url = lockFileApi,
|
||||||
headers = headers,
|
headers = headers,
|
||||||
body = patchJson.toString().toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()),
|
body = patchJson.toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull()),
|
||||||
)
|
)
|
||||||
|
|
||||||
// create lock file first
|
// create lock file first
|
||||||
@ -93,7 +108,6 @@ class SyncYomiSyncService(
|
|||||||
// update lock file acquired_by
|
// update lock file acquired_by
|
||||||
client.newCall(lockFileUpdate).execute()
|
client.newCall(lockFileUpdate).execute()
|
||||||
|
|
||||||
val json = Json { ignoreUnknownKeys = true }
|
|
||||||
var backoff = 2000L // Start with 2 seconds
|
var backoff = 2000L // Start with 2 seconds
|
||||||
val maxBackoff = 32000L // Maximum backoff time e.g., 32 seconds
|
val maxBackoff = 32000L // Maximum backoff time e.g., 32 seconds
|
||||||
var lockFile: LockFile
|
var lockFile: LockFile
|
||||||
@ -108,7 +122,6 @@ class SyncYomiSyncService(
|
|||||||
delay(backoff)
|
delay(backoff)
|
||||||
backoff = (backoff * 2).coerceAtMost(maxBackoff)
|
backoff = (backoff * 2).coerceAtMost(maxBackoff)
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (lockFile.status != SyncStatus.Success)
|
} while (lockFile.status != SyncStatus.Success)
|
||||||
|
|
||||||
// update lock file acquired_by
|
// update lock file acquired_by
|
||||||
|
@ -36,5 +36,4 @@ class SyncPreferences(
|
|||||||
|
|
||||||
return uniqueID
|
return uniqueID
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user