From 50971eeb0e90c2759c3c8808c0cedc49804cf005 Mon Sep 17 00:00:00 2001 From: acgnhik Date: Sun, 18 Dec 2022 18:20:29 +0800 Subject: [PATCH] chore: update packages and python --- .github/workflows/portable.yml | 4 ++-- Dockerfile | 2 +- Dockerfile.mirrors | 2 +- setup.cfg | 10 +++++----- src/blrec/web/main.py | 4 ++-- src/blrec/web/security.py | 28 +++++++++------------------- 6 files changed, 20 insertions(+), 30 deletions(-) diff --git a/.github/workflows/portable.yml b/.github/workflows/portable.yml index 73cf03e..68fef6a 100644 --- a/.github/workflows/portable.yml +++ b/.github/workflows/portable.yml @@ -8,7 +8,7 @@ on: env: FFMPEG_ARCHIVE_URL: https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-lgpl-shared.zip FFMPEG_ARCHIVE_NAME: ffmpeg-master-latest-win64-lgpl-shared.zip - PYTHON_ARCHIVE_URL: https://www.python.org/ftp/python/3.10.4/python-3.10.4-embed-amd64.zip + PYTHON_ARCHIVE_URL: https://www.python.org/ftp/python/3.11.1/python-3.11.1-embed-amd64.zip jobs: @@ -23,7 +23,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v3 with: - python-version: "3.10" + python-version: "3.11.1" - name: Download ffmpeg archive run: Invoke-WebRequest -Uri $($env:FFMPEG_ARCHIVE_URL) -OutFile ffmpeg.zip diff --git a/Dockerfile b/Dockerfile index 921d231..bbb2ba2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -FROM python:3.10-slim-buster +FROM python:3.11-slim-buster WORKDIR /app VOLUME ["/cfg", "/log", "/rec"] diff --git a/Dockerfile.mirrors b/Dockerfile.mirrors index 94e8ec7..ed27fac 100644 --- a/Dockerfile.mirrors +++ b/Dockerfile.mirrors @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -FROM python:3.10-slim-buster +FROM python:3.11-slim-buster WORKDIR /app VOLUME ["/cfg", "/log", "/rec"] diff --git a/setup.cfg b/setup.cfg index 5391fe9..7a10b9b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,13 +38,13 @@ install_requires = python-liquid >= 1.2.1, < 2.0.0 typing-extensions >= 3.10.0.0 ordered-set >= 4.1.0, < 5.0.0 - fastapi >= 0.70.0, < 0.71.0 + fastapi >= 0.88.0, < 0.89.0 email_validator >= 1.1.3, < 2.0.0 click < 8.1.0 - typer >= 0.4.1, < 0.5.0 + typer >= 0.7.0, < 0.8.0 aiohttp >= 3.8.1, < 4.0.0 requests >= 2.24.0, < 3.0.0 - aiofiles >= 0.8.0, < 0.9.0 + aiofiles >= 22.1.0, < 23.0.0 tenacity >= 8.0.1, < 9.0.0 colorama >= 0.4.4, < 0.5.0 humanize >= 3.13.1, < 4.0.0 @@ -52,14 +52,14 @@ install_requires = attrs >= 21.2.0, < 22.0.0 lxml >= 4.6.4, < 5.0.0 toml >= 0.10.2, < 0.11.0 - m3u8 >= 1.0.0, < 2.0.0 + m3u8 >= 3.3.0, < 4.0.0 av >= 10.0.0, < 11.0.0 jsonpath == 0.82 psutil >= 5.8.0, < 6.0.0 reactivex >= 4.0.0, < 5.0.0 bitarray >= 2.2.5, < 3.0.0 brotli >= 1.0.9, < 2.0.0 - uvicorn[standard] >= 0.15.0, < 0.16.0 + uvicorn[standard] >= 0.20.0, < 0.21.0 [options.extras_require] dev = diff --git a/src/blrec/web/main.py b/src/blrec/web/main.py index 8b7ed4b..9600157 100644 --- a/src/blrec/web/main.py +++ b/src/blrec/web/main.py @@ -137,12 +137,12 @@ api.include_router(update.router) class WebAppFiles(StaticFiles): - async def lookup_path( + def lookup_path( self, path: str ) -> Tuple[str, Optional[os.stat_result]]: if path == '404.html': path = 'index.html' - return await super().lookup_path(path) + return super().lookup_path(path) def file_response(self, full_path: str, *args, **kwargs) -> Response: # type: ignore # noqa # ignore MIME types from Windows registry diff --git a/src/blrec/web/security.py b/src/blrec/web/security.py index a284d57..ecc16bc 100644 --- a/src/blrec/web/security.py +++ b/src/blrec/web/security.py @@ -1,11 +1,10 @@ import logging import secrets -from typing import Optional, Set, Dict +from typing import Dict, Optional, Set -from fastapi import status, Request, Header +from fastapi import Header, Request, status from fastapi.exceptions import HTTPException - logger = logging.getLogger(__name__) @@ -21,34 +20,26 @@ attempting_clients: Dict[str, int] = {} async def authenticate( - request: Request, - x_api_key: Optional[str] = Header(None), + request: Request, x_api_key: Optional[str] = Header(None) ) -> None: assert api_key, 'api_key is required' if not x_api_key: raise HTTPException( - status_code=status.HTTP_401_UNAUTHORIZED, - detail='No api key', + status_code=status.HTTP_401_UNAUTHORIZED, detail='No api key' ) + assert request.client is not None, 'client should not be None' client_ip = request.client.host assert client_ip, 'client_ip is required' if client_ip in blacklist: - raise HTTPException( - status_code=status.HTTP_403_FORBIDDEN, - detail='Blacklisted', - ) + raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail='Blacklisted') if client_ip not in whitelist: - if ( - len(whitelist) >= MAX_WHITELIST or - len(blacklist) >= MAX_BLACKLIST - ): + if len(whitelist) >= MAX_WHITELIST or len(blacklist) >= MAX_BLACKLIST: raise HTTPException( status_code=status.HTTP_403_FORBIDDEN, - detail='Max clients allowed in whitelist or blacklist ' - 'will exceeded', + detail='Max clients allowed in whitelist or blacklist ' 'will exceeded', ) if len(attempting_clients) >= MAX_ATTEMPTING_CLIENTS: raise HTTPException( @@ -71,8 +62,7 @@ async def authenticate( if client_ip in whitelist: whitelist.remove(client_ip) raise HTTPException( - status_code=status.HTTP_401_UNAUTHORIZED, - detail='API key is invalid', + status_code=status.HTTP_401_UNAUTHORIZED, detail='API key is invalid' ) if client_ip in attempting_clients: