Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Divkix committed Mar 22, 2023
1 parent 740012e commit 63e3515
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 49 deletions.
6 changes: 4 additions & 2 deletions WebStreamer/bot/plugins/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ async def private_receive_handler(c: Client, m: Message):
"""
user = m.from_user
user_id = user.id
users_db = Users()
user_expire_time = await users_db.get_expire_time(user_id)

if (user_id != Vars.OWNER_ID) or (Vars.FLOODCONTROL_TIME_MINUTES != 0):
# spam check
Expand All @@ -89,6 +87,10 @@ async def private_receive_handler(c: Client, m: Message):
else f"https://{Vars.FQDN}:{Vars.PORT}/{random_url}"
)

# read from users database
users_db = Users()
user_expire_time = await users_db.get_expire_time(user_id)

await Downloads().add_download(
log_msg.id,
random_url,
Expand Down
12 changes: 0 additions & 12 deletions WebStreamer/db/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@ async def add_download(
)
return random_url

# TODO: Remove this function after 1 month (2021-08-01) because it's not used anywhere now
async def get_actual_link(self, link: str) -> str | None:
"""
Get the actual link from the database
:param link: The link to be searched
:return: The actual link
"""
document = await self.find_one({"random_link": link})
if not document:
return None
return document["link"]

async def get_msg_id(self, link: str) -> tuple[int, bool, datetime]:
"""
Get the message id from the database
Expand Down
35 changes: 0 additions & 35 deletions WebStreamer/server/stream_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,41 +43,6 @@ async def index_handler(_) -> web.StreamResponse:
)


# custom download page
# TODO: Remove this function after 1 month (2021-08-01) because it's not used anywhere now
@routes.get("/download-file-{random_link}")
@template("download_page.html")
async def stream_handler(request) -> web.StreamResponse | dict[str, str]:
"""
Stream Handler for WebStreamer, the '/download-file-*' route.
:param request: Request object
:return: StreamResponse object or a dict with appropriate data
"""
try:
random_link = request.match_info["random_link"]
user_id = extract_user_id_from_random_link(random_link)

# check if user is banned
if await Users().is_banned(user_id):
# user_id is the second part of the random_link separated by '-'
# if user is banned, return 403
return web.json_response(
{
"status": "user_banned",
"maintained_by": "@DivideProjects",
"telegram_bot": "@GetPublicLink_Robot",
},
status=403,
)

# get the actual link
real_link = await Downloads().get_actual_link(random_link)
return {"download_link": Vars.URL + real_link}
except ValueError as ef:
LOGGER.error(ef)
raise web.HTTPNotFound


# actual download link
@routes.get("/{real_link}")
async def stream_handler(request) -> web.StreamResponse:
Expand Down

0 comments on commit 63e3515

Please sign in to comment.