Skip to content

Commit

Permalink
fix: upload as ZIP does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Gorn committed Jun 7, 2024
1 parent 1f225ed commit 9a9979f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
5 changes: 3 additions & 2 deletions Bot/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from distutils.util import strtobool
import os
from dotenv import load_dotenv

Expand All @@ -21,8 +22,8 @@ class Config(object):
OWNER_ID = os.environ.get('OWNER_ID')

# Upload method (default to False)
AS_ZIP = bool(os.environ.get('AS_ZIP', False))
AS_ZIP = bool(strtobool(os.environ.get('AS_ZIP', 'False')))

PLUGINS = {'root': 'Bot.plugins'}

DOWNLOAD_DIR = "./downloads/"
18 changes: 8 additions & 10 deletions Bot/plugins/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import traceback
from ..functions.filters import OWNER_FILTER
from ..functions.helper import (
progress_for_pyrogram,
download_file,
absolute_paths,
send_media,
progress_for_pyrogram,
download_file,
absolute_paths,
send_media,
URL_REGEX
)
from ..config import Config
Expand All @@ -23,8 +23,7 @@ async def linkloader(bot: Client, update: Message):
dirs = f'{Config.DOWNLOAD_DIR}{update.from_user.id}'
if not os.path.isdir(dirs):
os.makedirs(dirs)
output_filename = str(update.from_user.id)
filename = f'{dirs}{output_filename}.zip'
filename = f'{dirs}.zip'
pablo = await update.reply_text('Downloading...')
urls = URL_REGEX.findall(update.text)
rm, total, up = len(urls), len(urls), 0
Expand All @@ -44,7 +43,7 @@ async def linkloader(bot: Client, update: Message):
client.logger.warning(traceback.format_exc())
await pablo.edit_text('Uploading...')
if Config.AS_ZIP:
shutil.make_archive(output_filename, 'zip', dirs)
shutil.make_archive(dirs, 'zip', dirs)
start_time = time.time()
await update.reply_document(
filename,
Expand Down Expand Up @@ -87,8 +86,7 @@ async def loader(bot: Client, update: Message):
os.makedirs(dirs)
if not update.document.file_name.endswith(('.txt', '.text')):
return
output_filename = update.document.file_name[:-4]
filename = f'{Config.DOWNLOAD_DIR}{output_filename}.zip'
filename = f'{Config.DOWNLOAD_DIR}.zip'
pablo = await update.reply_text('Downloading...')
fl = await update.download()
with open(fl) as f:
Expand All @@ -111,7 +109,7 @@ async def loader(bot: Client, update: Message):
client.logger.warning(traceback.format_exc())
await pablo.edit_text('Uploading...')
if Config.AS_ZIP:
shutil.make_archive(output_filename, 'zip', dirs)
shutil.make_archive(dirs, 'zip', dirs)
start_time = time.time()
try:
await update.reply_document(
Expand Down

0 comments on commit 9a9979f

Please sign in to comment.