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"
|
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) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue