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
6237fefcd4
5
app/proguard-rules.pro
vendored
5
app/proguard-rules.pro
vendored
@ -80,4 +80,7 @@
|
|||||||
-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.** { *; }
|
@ -114,23 +114,39 @@ class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: Sync
|
|||||||
val drive = googleDriveService.driveService
|
val drive = googleDriveService.driveService
|
||||||
|
|
||||||
if (drive == null) {
|
if (drive == null) {
|
||||||
logcat(LogPriority.ERROR) { "Google Drive service not initialized" }
|
logcat(LogPriority.DEBUG) { "Google Drive service not initialized" }
|
||||||
throw Exception(context.stringResource(MR.strings.google_drive_not_signed_in))
|
throw Exception(context.stringResource(MR.strings.google_drive_not_signed_in))
|
||||||
}
|
}
|
||||||
|
|
||||||
val fileList = getAppDataFileList(drive)
|
val fileList = getAppDataFileList(drive)
|
||||||
if (fileList.isEmpty()) {
|
if (fileList.isEmpty()) {
|
||||||
|
logcat(LogPriority.INFO) { "No files found in app data" }
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
val gdriveFileId = fileList[0].id
|
val gdriveFileId = fileList[0].id
|
||||||
|
logcat(LogPriority.DEBUG) { "Google Drive File ID: $gdriveFileId" }
|
||||||
|
|
||||||
val outputStream = ByteArrayOutputStream()
|
val outputStream = ByteArrayOutputStream()
|
||||||
drive.files().get(gdriveFileId).executeMediaAndDownloadTo(outputStream)
|
try {
|
||||||
|
drive.files().get(gdriveFileId).executeMediaAndDownloadTo(outputStream)
|
||||||
|
logcat(LogPriority.DEBUG) { "File downloaded successfully" }
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logcat(LogPriority.ERROR) { "Error downloading file: ${e.message}" }
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
val gzipInputStream = GZIPInputStream(ByteArrayInputStream(outputStream.toByteArray()))
|
try {
|
||||||
val gson = Gson()
|
val gzipInputStream = GZIPInputStream(ByteArrayInputStream(outputStream.toByteArray()))
|
||||||
gson.fromJson(gzipInputStream.reader(Charsets.UTF_8), SyncData::class.java)
|
val gson = Gson()
|
||||||
|
val syncData = gson.fromJson(gzipInputStream.reader(Charsets.UTF_8), SyncData::class.java)
|
||||||
|
logcat(LogPriority.DEBUG) { "JSON deserialized successfully" }
|
||||||
|
syncData
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logcat(LogPriority.ERROR) { "Failed to convert json to sync data: ${e.message}" }
|
||||||
|
throw Exception(e.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user