prod: minor problem fixes

This commit is contained in:
ZhymabekRoman 2024-06-10 20:57:31 +06:00
parent 841d828cb5
commit 9ea3b316de
7 changed files with 18 additions and 21 deletions

View file

@ -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:

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)
# sentry_sdk.capture_exception(ex)
return await generate_error(message, status_code=status_code)

View file

@ -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"}