diff --git a/WebStreamer/bot/plugins/stream.py b/WebStreamer/bot/plugins/stream.py index 3bd38d5..39e033f 100644 --- a/WebStreamer/bot/plugins/stream.py +++ b/WebStreamer/bot/plugins/stream.py @@ -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 @@ -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, diff --git a/WebStreamer/db/downloads.py b/WebStreamer/db/downloads.py index f189221..c2aba06 100644 --- a/WebStreamer/db/downloads.py +++ b/WebStreamer/db/downloads.py @@ -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 diff --git a/WebStreamer/server/stream_routes.py b/WebStreamer/server/stream_routes.py index 84d09f2..61797ba 100644 --- a/WebStreamer/server/stream_routes.py +++ b/WebStreamer/server/stream_routes.py @@ -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: