mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
feat: add remote sync capability - fix file exists check
This commit is contained in:
parent
13978f8203
commit
de3019b1d8
1 changed files with 10 additions and 6 deletions
|
@ -204,7 +204,7 @@ class GoogleDriveApi(index: Int) :
|
|||
fileMetadata.mimeType = "application/json"
|
||||
val fileContent = FileContent("application/json", ioFile)
|
||||
|
||||
val fileId = getOrCreateSyncFileId(drive, loginData)
|
||||
val fileId = getOrFindExistingSyncFileId(drive, loginData)
|
||||
if (fileId != null) {
|
||||
try {
|
||||
val file = drive.files()
|
||||
|
@ -232,7 +232,7 @@ class GoogleDriveApi(index: Int) :
|
|||
val drive = getDriveService() ?: return
|
||||
val loginData = getLatestLoginData() ?: return
|
||||
|
||||
val existingFileId = getOrCreateSyncFileId(drive, loginData)
|
||||
val existingFileId = getOrFindExistingSyncFileId(drive, loginData)
|
||||
val existingFile = if (existingFileId != null) {
|
||||
try {
|
||||
drive.files().get(existingFileId)
|
||||
|
@ -261,11 +261,15 @@ class GoogleDriveApi(index: Int) :
|
|||
uploadSyncData()
|
||||
}
|
||||
|
||||
private fun getOrCreateSyncFileId(drive: Drive, loginData: InAppOAuth2API.LoginData): String? {
|
||||
private fun getOrFindExistingSyncFileId(
|
||||
drive: Drive,
|
||||
loginData: InAppOAuth2API.LoginData
|
||||
): String? {
|
||||
if (loginData.syncFileId != null) {
|
||||
val verified = drive.files().get(loginData.syncFileId)
|
||||
if (verified != null) {
|
||||
return loginData.syncFileId
|
||||
try {
|
||||
val verified = drive.files().get(loginData.syncFileId).execute()
|
||||
return verified.id
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue