Use proper url-encoding methods to replace special characters from url

Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
This commit is contained in:
lzzy12 2020-03-20 17:03:29 +05:30
parent 4207f139e4
commit 898977df97
2 changed files with 5 additions and 6 deletions

View File

@ -7,11 +7,10 @@ from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from googleapiclient.http import MediaFileUpload
from tenacity import *
from bot import LOGGER, parent_id, DOWNLOAD_DIR, IS_TEAM_DRIVE, INDEX_URL, DOWNLOAD_STATUS_UPDATE_INTERVAL
from bot.helper.ext_utils.bot_utils import *
from bot.helper.ext_utils.fs_utils import get_mime_type
import requests
logging.getLogger('googleapiclient.discovery').setLevel(logging.ERROR)
@ -239,13 +238,13 @@ class GoogleDriveHelper:
msg += f"⁍ <a href='https://drive.google.com/drive/folders/{file.get('id')}'>{file.get('name')}" \
f"</a> (folder)"
if INDEX_URL is not None:
url = f'{INDEX_URL}/{file.get("name")}/'
url = requests.utils.requote_uri(f'{INDEX_URL}/{file.get("name")}/')
msg += f' | <a href="{url}"> Index URL</a>'
else:
msg += f"⁍ <a href='https://drive.google.com/uc?id={file.get('id')}" \
f"&export=download'>{file.get('name')}</a> ({get_readable_file_size(int(file.get('size')))})"
if INDEX_URL is not None:
url = f'{INDEX_URL}/{file.get("name")}'
url = requests.utils.requote_uri(f'{INDEX_URL}/{file.get("name")}')
msg += f' | <a href="{url}"> Index URL</a>'
msg += '\n'
results.append(file)

View File

@ -15,6 +15,7 @@ import pathlib
import os
from bot.helper.mirror_utils.download_utils.direct_link_generator import direct_link_generator
from bot.helper.ext_utils.exceptions import DirectDownloadLinkException
import requests
class MirrorListener(listeners.MirrorListeners):
@ -96,8 +97,7 @@ class MirrorListener(listeners.MirrorListeners):
msg = f'<a href="{link}">{download_dict[self.uid].name()}</a> ({download_dict[self.uid].size()})'
LOGGER.info(f'Done Uploading {download_dict[self.uid].name()}')
if INDEX_URL is not None:
share_url = f'{INDEX_URL}/{download_dict[self.uid].name()}'
share_url = share_url.replace(' ', '%20')
share_url = requests.utils.requote_uri(f'{INDEX_URL}/{download_dict[self.uid].name()}')
if os.path.isdir(f'{DOWNLOAD_DIR}/{self.uid}/{download_dict[self.uid].name()}'):
share_url += '/'
msg += f'\n\n Shareable link: <a href="{share_url}">here</a>'