mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-15 15:02:49 +01:00
Merge branch 'sync-part-final' into feat/add-sync-triggers-experimental
This commit is contained in:
commit
dd301c465b
5
app/proguard-rules.pro
vendored
5
app/proguard-rules.pro
vendored
@ -80,7 +80,4 @@
|
|||||||
-keep class com.google.api.services.** { *; }
|
-keep class com.google.api.services.** { *; }
|
||||||
|
|
||||||
# Google OAuth
|
# Google OAuth
|
||||||
-keep class com.google.api.client.** { *; }
|
-keep class com.google.api.client.** { *; }
|
||||||
|
|
||||||
# Keep backup models, otherwise gson fails on release builds.
|
|
||||||
-keep class eu.kanade.tachiyomi.data.backup.models.** { *; }
|
|
@ -18,11 +18,10 @@ import com.google.api.client.json.jackson2.JacksonFactory
|
|||||||
import com.google.api.services.drive.Drive
|
import com.google.api.services.drive.Drive
|
||||||
import com.google.api.services.drive.DriveScopes
|
import com.google.api.services.drive.DriveScopes
|
||||||
import com.google.api.services.drive.model.File
|
import com.google.api.services.drive.model.File
|
||||||
import com.google.gson.Gson
|
|
||||||
import com.google.gson.stream.JsonWriter
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import logcat.logcat
|
import logcat.logcat
|
||||||
@ -35,7 +34,6 @@ import java.io.ByteArrayInputStream
|
|||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
import java.io.OutputStreamWriter
|
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.util.zip.GZIPInputStream
|
import java.util.zip.GZIPInputStream
|
||||||
import java.util.zip.GZIPOutputStream
|
import java.util.zip.GZIPOutputStream
|
||||||
@ -139,12 +137,14 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
|
|||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
val gzipInputStream = GZIPInputStream(ByteArrayInputStream(outputStream.toByteArray()))
|
val gzipInputStream = GZIPInputStream(ByteArrayInputStream(outputStream.toByteArray()))
|
||||||
val gson = Gson()
|
val jsonString = gzipInputStream.bufferedReader(Charsets.UTF_8).use { it.readText() }
|
||||||
val syncData = gson.fromJson(gzipInputStream.reader(Charsets.UTF_8), SyncData::class.java)
|
val syncData = json.decodeFromString(SyncData.serializer(), jsonString)
|
||||||
logcat(LogPriority.DEBUG) { "JSON deserialized successfully" }
|
logcat(LogPriority.DEBUG) { "JSON deserialized successfully" }
|
||||||
syncData
|
syncData
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logcat(LogPriority.ERROR) { "Failed to convert json to sync data: ${e.message}" }
|
logcat(
|
||||||
|
LogPriority.ERROR,
|
||||||
|
) { "Failed to convert json to sync data with kotlinx.serialization: ${e.message}" }
|
||||||
throw Exception(e.message)
|
throw Exception(e.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,13 +158,11 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
|
|||||||
val byteArrayOutputStream = ByteArrayOutputStream()
|
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
|
val jsonData = json.encodeToString(syncData)
|
||||||
val gzipOutputStream = GZIPOutputStream(byteArrayOutputStream)
|
val gzipOutputStream = GZIPOutputStream(byteArrayOutputStream)
|
||||||
val jsonWriter = JsonWriter(OutputStreamWriter(gzipOutputStream, Charsets.UTF_8))
|
gzipOutputStream.write(jsonData.toByteArray(Charsets.UTF_8))
|
||||||
val gson = Gson().newBuilder().serializeNulls().create()
|
gzipOutputStream.close()
|
||||||
|
logcat(LogPriority.DEBUG) { "JSON serialized successfully" }
|
||||||
jsonWriter.use { jWriter ->
|
|
||||||
gson.toJson(syncData, SyncData::class.java, jWriter)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val byteArrayContent = ByteArrayContent("application/octet-stream", byteArrayOutputStream.toByteArray())
|
val byteArrayContent = ByteArrayContent("application/octet-stream", byteArrayOutputStream.toByteArray())
|
||||||
|
Loading…
Reference in New Issue
Block a user