Skip to content

Commit

Permalink
Fix bot not cloning data into destination drives
Browse files Browse the repository at this point in the history
  • Loading branch information
l3v11 authored May 30, 2022
1 parent 3132d9d commit b4d4172
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions bot/helper/drive_utils/gdriveTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from telegram import InlineKeyboardMarkup
from telegraph.exceptions import RetryAfterError

from google.auth.transport.requests import Request
from google.oauth2 import service_account
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
Expand Down Expand Up @@ -66,8 +67,10 @@ def authorize(self):
if not USE_SERVICE_ACCOUNTS:
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', self.__OAUTH_SCOPE)
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
LOGGER.error("token.json file is missing")
LOGGER.error("The token.json file is missing")
else:
LOGGER.info(f"Authorizing with {SERVICE_ACCOUNT_INDEX}.json file")
creds = service_account.Credentials.from_service_account_file(
Expand All @@ -81,7 +84,11 @@ def alt_authorize(self):
if os.path.exists('token.json'):
LOGGER.info("Authorizing with token.json file")
creds = Credentials.from_authorized_user_file('token.json', self.__OAUTH_SCOPE)
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
return build('drive', 'v3', credentials=creds, cache_discovery=False)
else:
LOGGER.error("The token.json file is missing")
return None

@staticmethod
Expand Down Expand Up @@ -274,7 +281,7 @@ def clone(self, link, key):
name = meta.get("name")
mime_type = meta.get("mimeType")
if mime_type == self.__G_DRIVE_DIR_MIME_TYPE:
dir_id = self.create_directory(meta.get('name'), PARENT_ID)
dir_id = self.create_directory(meta.get('name'), parent_id)
self.cloneFolder(meta.get('name'), meta.get('name'), meta.get('id'), dir_id)
durl = self.__G_DRIVE_DIR_BASE_DOWNLOAD_URL.format(dir_id)
if self.is_cancelled:
Expand All @@ -292,7 +299,7 @@ def clone(self, link, key):
url = f'{index_url}/{url_path}/'
msg += f'<b> | <a href="{url}">Index Link</a></b>'
else:
file = self.copyFile(meta.get('id'), PARENT_ID)
file = self.copyFile(meta.get('id'), parent_id)
msg += f'<b>Name:</b> <code>{file.get("name")}</code>'
if mime_type is None:
mime_type = 'File'
Expand Down

0 comments on commit b4d4172

Please sign in to comment.