diff --git a/core/medium_parser/utils.py b/core/medium_parser/utils.py index e283dbc..6ab55ce 100644 --- a/core/medium_parser/utils.py +++ b/core/medium_parser/utils.py @@ -227,11 +227,11 @@ def basic_hex_check(hex_string: str) -> bool: @lru_cache(maxsize=100) def extract_hex_string(input_string: str) -> str: # First try to find a hexadecimal string preceded by a '-' - match = re.search(r'-(\b[a-fA-F0-9]{8,12}\b)', input_string) + match = re.findall(r'-(\b[a-fA-F0-9]{8,12}\b)', input_string) if not match: # If no match, try to find a hexadecimal string without the '-' - match = re.search(r'(\b[a-fA-F0-9]{8,12}\b)', input_string) - return match.group(1) if match else None + match = re.findall(r'(\b[a-fA-F0-9]{8,12}\b)', input_string) + return match[-1] if match else None async def resolve_medium_short_link(short_url_id: str, timeout: int = 5) -> str: diff --git a/requirements.txt b/requirements.txt index f30f013..14a3837 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,11 @@ pickledb==0.9.2 html5lib==1.1 -fastapi-limiter==0.1.5 sentry-sdk[fastapi]==1.29.2 -loguru==0.6.0 # due to: https://github.com/Delgan/loguru/issues/916 -uvicorn==0.20.0 +loguru==0.6.0 # due to: https://github.com/Delgan/loguru/issues/916 +uvicorn==0.27.1 +anyio<=4.0.0 # Workaround to: https://github.getafreenode.com/tiangolo/fastapi/discussions/11652 Jinja2==3.1.2 -fastapi==0.91.0 -starlette==0.24.0 +fastapi==0.108.0 gunicorn==21.2.0 redis[hiredis]==4.6.0 xkcdpass==1.19.3 diff --git a/server/main.py b/server/main.py index bc3bd71..2effb19 100644 --- a/server/main.py +++ b/server/main.py @@ -3,8 +3,8 @@ import sentry_sdk from fastapi.exceptions import HTTPException from fastapi import FastAPI, Depends, APIRouter from loguru import logger -from fastapi_limiter import FastAPILimiter -from fastapi_limiter.depends import RateLimiter +# from fastapi_limiter import FastAPILimiter +# from fastapi_limiter.depends import RateLimiter from server import config, redis_storage from server.exceptions.main import register_main_error_handler from server.handlers.main import register_main_router diff --git a/server/middlewares/logger.py b/server/middlewares/logger.py index be744b5..5c3a6de 100644 --- a/server/middlewares/logger.py +++ b/server/middlewares/logger.py @@ -15,15 +15,8 @@ from server.utils.error import generate_error from server.utils.utils import string_to_number_ascii -async def set_body(request: Request, body: bytes): - async def receive() -> Message: - return {"type": "http.request", "body": body} - request._receive = receive - - async def get_body(request: Request) -> bytes: body = await request.body() - await set_body(request, body) return body diff --git a/server/utils/anti_bot.py b/server/utils/anti_bot.py index a289440..4b0761e 100644 --- a/server/utils/anti_bot.py +++ b/server/utils/anti_bot.py @@ -33,6 +33,9 @@ bot_signatures = { def filter_bots(details: str) -> bool: + if not details: + return True + is_bot = any(bot_signature in details for bot_signature in bot_signatures) logger.debug(f"{details} is a bot: {is_bot}") return is_bot diff --git a/server/utils/exceptions.py b/server/utils/exceptions.py index e709e9f..5fd26c7 100644 --- a/server/utils/exceptions.py +++ b/server/utils/exceptions.py @@ -4,7 +4,7 @@ from loguru import logger from server.utils.error import generate_error -async def handle_exception(ex, message="An error occurred", status_code=500): +async def handle_exception(ex, message="An error occurred", status_code=500, quiet: bool = False): logger.exception(ex) - sentry_sdk.capture_exception(ex) - return await generate_error(message, status_code=status_code) \ No newline at end of file + # sentry_sdk.capture_exception(ex) + return await generate_error(message, status_code=status_code) diff --git a/test.py b/test.py index 2ca9821..76acb3a 100644 --- a/test.py +++ b/test.py @@ -14,7 +14,9 @@ url_for_test = { "https://medium.com/@aleb/how-to-generate-random-user-agents-with-an-api-22aad3d232cb", "https://medium.com/angular-in-depth/the-best-way-to-unsubscribe-rxjs-observable-in-the-angular-applications-d8f9aa42f6a0", "515dd5a43948", # full address: https://medium.com/macoclock/12-macos-apps-so-good-you-will-wonder-how-they-are-free-515dd5a43948 - "https://anudeep-vysyaraju.medium.com/how-any-gitamite-can-get-free-linkedin-premium-membership-d4222bd1a0b3" # <--- Check for non properly aligned emojies + "https://anudeep-vysyaraju.medium.com/how-any-gitamite-can-get-free-linkedin-premium-membership-d4222bd1a0b3", # <--- Check for non properly aligned emojies + "http://freedium.cfd/https://johndanielraines.medium.com/be-an-engineer-not-a-frameworker-c58fe28d0c88", + "https://medium.com/coding-beauty/parseint-strange-behavior-cdff5e1f9ff7" # <---- Title renderer some weird characters } blacklist_url = {"51e23c5a2aac"}