feat: add remote sync capability - fix file exists check

This commit is contained in:
Martin Filo 2023-05-08 15:43:52 +02:00
parent 13978f8203
commit de3019b1d8

View file

@ -204,7 +204,7 @@ class GoogleDriveApi(index: Int) :
fileMetadata.mimeType = "application/json" fileMetadata.mimeType = "application/json"
val fileContent = FileContent("application/json", ioFile) val fileContent = FileContent("application/json", ioFile)
val fileId = getOrCreateSyncFileId(drive, loginData) val fileId = getOrFindExistingSyncFileId(drive, loginData)
if (fileId != null) { if (fileId != null) {
try { try {
val file = drive.files() val file = drive.files()
@ -232,7 +232,7 @@ class GoogleDriveApi(index: Int) :
val drive = getDriveService() ?: return val drive = getDriveService() ?: return
val loginData = getLatestLoginData() ?: return val loginData = getLatestLoginData() ?: return
val existingFileId = getOrCreateSyncFileId(drive, loginData) val existingFileId = getOrFindExistingSyncFileId(drive, loginData)
val existingFile = if (existingFileId != null) { val existingFile = if (existingFileId != null) {
try { try {
drive.files().get(existingFileId) drive.files().get(existingFileId)
@ -261,11 +261,15 @@ class GoogleDriveApi(index: Int) :
uploadSyncData() uploadSyncData()
} }
private fun getOrCreateSyncFileId(drive: Drive, loginData: InAppOAuth2API.LoginData): String? { private fun getOrFindExistingSyncFileId(
drive: Drive,
loginData: InAppOAuth2API.LoginData
): String? {
if (loginData.syncFileId != null) { if (loginData.syncFileId != null) {
val verified = drive.files().get(loginData.syncFileId) try {
if (verified != null) { val verified = drive.files().get(loginData.syncFileId).execute()
return loginData.syncFileId return verified.id
} catch (_: Exception) {
} }
} }