Fixed bugs in MirrorListener
This commit is contained in:
parent
b84ffcc416
commit
1543da735c
|
|
@ -51,14 +51,14 @@ class MirrorListener(listeners.MirrorListeners):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
path = f'{DOWNLOAD_DIR}{self.uid}/{download_dict[self.uid].name()}'
|
path = f'{DOWNLOAD_DIR}{self.uid}/{download_dict[self.uid].name()}'
|
||||||
name = pathlib.PurePath(path).name
|
up_name = pathlib.PurePath(path).name
|
||||||
with download_dict_lock:
|
with download_dict_lock:
|
||||||
LOGGER.info(f"Upload Name : {name}")
|
LOGGER.info(f"Upload Name : {up_name}")
|
||||||
drive = gdriveTools.GoogleDriveHelper(name, self)
|
drive = gdriveTools.GoogleDriveHelper(up_name, self)
|
||||||
upload_status = UploadStatus(drive, size, self.uid)
|
upload_status = UploadStatus(drive, size, self.uid)
|
||||||
download_dict[self.uid] = upload_status
|
download_dict[self.uid] = upload_status
|
||||||
update_all_messages()
|
update_all_messages()
|
||||||
drive.upload(name)
|
drive.upload(up_name)
|
||||||
|
|
||||||
def onDownloadError(self, error):
|
def onDownloadError(self, error):
|
||||||
LOGGER.info(self.update.effective_chat.id)
|
LOGGER.info(self.update.effective_chat.id)
|
||||||
|
|
@ -72,17 +72,18 @@ class MirrorListener(listeners.MirrorListeners):
|
||||||
LOGGER.info(str(download_dict))
|
LOGGER.info(str(download_dict))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOGGER.error(str(e))
|
LOGGER.error(str(e))
|
||||||
|
pass
|
||||||
count = len(download_dict)
|
count = len(download_dict)
|
||||||
if count == 0:
|
|
||||||
self.clean()
|
|
||||||
if self.message.from_user.username:
|
if self.message.from_user.username:
|
||||||
uname = f"@{self.message.from_user.username}"
|
uname = f"@{self.message.from_user.username}"
|
||||||
else:
|
else:
|
||||||
uname = f'<a href="tg://user?id={self.message.from_user.id}">{self.message.from_user.first_name}</a>'
|
uname = f'<a href="tg://user?id={self.message.from_user.id}">{self.message.from_user.first_name}</a>'
|
||||||
msg = f"{uname} your download has been stopped due to: {error}"
|
msg = f"{uname} your download has been stopped due to: {error}"
|
||||||
if count != 0:
|
|
||||||
update_all_messages()
|
|
||||||
sendMessage(msg, self.bot, self.update)
|
sendMessage(msg, self.bot, self.update)
|
||||||
|
if count == 0:
|
||||||
|
self.clean()
|
||||||
|
else:
|
||||||
|
update_all_messages()
|
||||||
|
|
||||||
def onUploadStarted(self):
|
def onUploadStarted(self):
|
||||||
pass
|
pass
|
||||||
|
|
@ -97,39 +98,32 @@ class MirrorListener(listeners.MirrorListeners):
|
||||||
if os.path.isdir(f'{DOWNLOAD_DIR}/{self.uid}/{download_dict[self.uid].name()}'):
|
if os.path.isdir(f'{DOWNLOAD_DIR}/{self.uid}/{download_dict[self.uid].name()}'):
|
||||||
share_url += '/'
|
share_url += '/'
|
||||||
msg += f'\n\n Shareable link: <a href="{share_url}">here</a>'
|
msg += f'\n\n Shareable link: <a href="{share_url}">here</a>'
|
||||||
|
|
||||||
if len(download_dict) == 0:
|
|
||||||
self.clean()
|
|
||||||
else:
|
|
||||||
update_all_messages()
|
|
||||||
sendMessage(msg, self.bot, self.update)
|
|
||||||
try:
|
try:
|
||||||
with download_dict_lock:
|
|
||||||
fs_utils.clean_download(download_dict[self.uid].path())
|
fs_utils.clean_download(download_dict[self.uid].path())
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
del download_dict[self.uid]
|
del download_dict[self.uid]
|
||||||
count = len(download_dict)
|
count = len(download_dict)
|
||||||
|
sendMessage(msg,self.bot,self.update)
|
||||||
if count == 0:
|
if count == 0:
|
||||||
self.clean()
|
self.clean()
|
||||||
else:
|
else:
|
||||||
update_all_messages()
|
update_all_messages()
|
||||||
except FileNotFoundError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def onUploadError(self, error: str):
|
def onUploadError(self, error: str):
|
||||||
LOGGER.error(error)
|
LOGGER.error(error)
|
||||||
sendMessage(error, self.bot, self.update)
|
sendMessage(error, self.bot, self.update)
|
||||||
with download_dict_lock:
|
with download_dict_lock:
|
||||||
del download_dict[self.message.message_id]
|
|
||||||
if len(download_dict) == 0:
|
|
||||||
self.clean()
|
|
||||||
else:
|
|
||||||
update_all_messages()
|
|
||||||
try:
|
try:
|
||||||
with download_dict_lock:
|
|
||||||
fs_utils.clean_download(download_dict[self.uid].path())
|
fs_utils.clean_download(download_dict[self.uid].path())
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
del download_dict[self.message.message_id]
|
||||||
|
count = len(download_dict)
|
||||||
|
if len(count) == 0:
|
||||||
|
self.clean()
|
||||||
|
else:
|
||||||
|
update_all_messages()
|
||||||
|
|
||||||
def _mirror(bot, update, isTar=False):
|
def _mirror(bot, update, isTar=False):
|
||||||
message_args = update.message.text.split(' ')
|
message_args = update.message.text.split(' ')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue