Skip to content

Commit

Permalink
perf: check whether user has logged in before processing the request
Browse files Browse the repository at this point in the history
  • Loading branch information
Itz-fork committed Dec 28, 2023
1 parent 7020218 commit d5d239b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
2 changes: 0 additions & 2 deletions megadl/lib/megatools.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ def __shellExec(self, cmd: str, chat_id: int = None, msg_id: int = None, **kwarg
self.client.edit_message_text(
chat_id, msg_id, f"**Process info:** \n`{out}`", **kwargs
)
# run.terminate()
# run.wait()
except:
pass
except FileNotFoundError:
Expand Down
2 changes: 2 additions & 0 deletions megadl/modules/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ async def close_gb(client: MeganzClient, query: CallbackQuery):
try:
# Remove user from global temp db
dtmp = client.glob_tmp.get(_mid)

# cancel if user has a download running
prcid = client.mega_running.get(query.message.chat.id)
if prcid:
await kill_family(prcid)

# Remove download folder of the user
if dtmp:
await client.full_cleanup(dtmp[1], _mid)
Expand Down
23 changes: 12 additions & 11 deletions megadl/modules/mega_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,7 @@ async def dl_from_cb(client: MeganzClient, query: CallbackQuery):
url = dtmp[0]
dlid = dtmp[1]
qcid = query.message.chat.id

# Create unique download folder
if not path.isdir(dlid):
makedirs(dlid)

# Download the file/folder
resp = await query.edit_message_text(
"Your download is starting 📥...", reply_markup=None
)


# weird workaround to add support for private mode
conf = None
if client.is_public:
Expand All @@ -71,6 +62,16 @@ async def dl_from_cb(client: MeganzClient, query: CallbackQuery):
)
if udoc:
conf = f"--username {client.cipher.decrypt(udoc[0]).decode()} --password {client.cipher.decrypt(udoc[1]).decode()}"

# Create unique download folder
if not path.isdir(dlid):
makedirs(dlid)

# Download the file/folder
resp = await query.edit_message_text(
"Your download is starting 📥...", reply_markup=None
)

cli = MegaTools(client, conf)

f_list = None
Expand Down Expand Up @@ -105,7 +106,7 @@ async def dl_from_cb(client: MeganzClient, query: CallbackQuery):
await resp.edit("Trying to upload now 📤...")
await client.send_files(f_list, qcid, resp.id)
await client.full_cleanup(dlid, _mid)
# await resp.delete()
await resp.delete()


@MeganzClient.on_callback_query(filters.regex(r"info_mg?.+"))
Expand Down
23 changes: 12 additions & 11 deletions megadl/modules/mega_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ async def to_up_cb(client: MeganzClient, query: CallbackQuery):
_mid = int(query.data.split("-")[1])
qcid = query.message.chat.id
qmid = query.message.id

# weird workaround to add support for private mode
conf = None
if client.is_public:
udoc = await client.database.is_there(qcid, True)
if not udoc:
return await query.edit_message_text(
"You need to be logged in first to download this file 😑"
)
if udoc:
conf = f"--username {client.cipher.decrypt(udoc['email']).decode()} --password {client.cipher.decrypt(udoc['password']).decode()}"

strtim = time()
msg = await client.get_messages(qcid, _mid)
# Status msg
Expand All @@ -68,17 +80,6 @@ async def to_up_cb(client: MeganzClient, query: CallbackQuery):
dl_path = await dl.download(msg.text, client.dl_loc, client, (qcid, qmid))

# Upload the file
# weird workaround to add support for private mode
conf = None
if client.is_public:
udoc = await client.database.is_there(qcid, True)
if not udoc:
return await query.edit_message_text(
"You need to be logged in first to download this file 😑"
)
if udoc:
conf = f"--username {client.cipher.decrypt(udoc['email']).decode()} --password {client.cipher.decrypt(udoc['password']).decode()}"

cli = MegaTools(client, conf)

limk = await cli.upload(dl_path, qcid, qmid)
Expand Down

0 comments on commit d5d239b

Please sign in to comment.