Skip to content

Commit

Permalink
Count After Upload (breakdowns#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
anasty17 authored Jun 4, 2021
1 parent f8179c8 commit b490a58
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 12 additions & 1 deletion bot/helper/mirror_utils/upload_utils/gdriveTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ def upload_file(self, file_path, file_name, mime_type, parent_id):
'description': 'Uploaded by Slam Mirror Bot',
'mimeType': mime_type,
}
try:
self.typee = file_metadata['mimeType']
except:
self.typee = 'File'
if parent_id is not None:
file_metadata['parents'] = [parent_id]

Expand Down Expand Up @@ -206,6 +210,8 @@ def upload_file(self, file_path, file_name, mime_type, parent_id):
return download_url

def upload(self, file_name: str):
self.total_files = 0
self.total_folders = 0
if USE_SERVICE_ACCOUNTS:
self.service_account_count = len(os.listdir("accounts"))
self.__listener.onUploadStarted()
Expand Down Expand Up @@ -253,7 +259,10 @@ def upload(self, file_name: str):
finally:
self.updater.cancel()
LOGGER.info(download_dict)
self.__listener.onUploadComplete(link, size)
files = self.total_files
folders = self.total_folders
typ = self.typee
self.__listener.onUploadComplete(link, size, files, folders, typ)
LOGGER.info("Deleting downloaded file/folder..")
return link

Expand Down Expand Up @@ -447,11 +456,13 @@ def upload_dir(self, input_directory, parent_id):
if os.path.isdir(current_file_name):
current_dir_id = self.create_directory(item, parent_id)
new_id = self.upload_dir(current_file_name, current_dir_id)
self.total_folders += 1
else:
mime_type = get_mime_type(current_file_name)
file_name = current_file_name.split("/")[-1]
# current_file_name will have the full path
self.upload_file(current_file_name, file_name, mime_type, parent_id)
self.total_files += 1
new_id = parent_id
return new_id

Expand Down
7 changes: 6 additions & 1 deletion bot/modules/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def onUploadStarted(self):
def onUploadProgress(self):
pass

def onUploadComplete(self, link: str, size):
def onUploadComplete(self, link: str, size, files, folders, typ):
with download_dict_lock:
msg = f'<b>Filename: </b><code>{download_dict[self.uid].name()}</code>\n<b>Size: </b><code>{size}</code>'
buttons = button_build.ButtonMaker()
Expand All @@ -161,6 +161,11 @@ def onUploadComplete(self, link: str, size):
share_url = f'{INDEX_URL}/{url_path}'
if os.path.isdir(f'{DOWNLOAD_DIR}/{self.uid}/{download_dict[self.uid].name()}'):
share_url += '/'
msg += "\n\n<b>Type: </b>Folder"
msg += f"\n<b>SubFolders: </b>{folders}"
msg += f"\n<b>Files: </b>{files}"
else:
msg += f"\n\n<b>Type: </b>{typ}"
if SHORTENER is not None and SHORTENER_API is not None:
siurl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, share_url)).text
buttons.buildbutton("⚡Index Link⚡", siurl)
Expand Down

0 comments on commit b490a58

Please sign in to comment.