From 502ca3ede18e55e13c4aec58a1143b668e82009a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Wed, 4 Sep 2024 17:54:14 +0800 Subject: [PATCH] feat: revert upload detect (#336) --- .github/workflows/pr-tests.yml | 5 ----- docker/Dockerfile.aws.lambda | 4 ---- server/aws/router.py | 11 ----------- server/requirements.txt | 1 - 4 files changed, 21 deletions(-) diff --git a/.github/workflows/pr-tests.yml b/.github/workflows/pr-tests.yml index 57cec69c..d3436043 100644 --- a/.github/workflows/pr-tests.yml +++ b/.github/workflows/pr-tests.yml @@ -45,11 +45,6 @@ jobs: with: python-version: '3.12.0' - - name: Install libmagic - run: | - sudo apt-get update - sudo apt-get install -y libmagic1 - - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/docker/Dockerfile.aws.lambda b/docker/Dockerfile.aws.lambda index 892524eb..b0b10f5d 100644 --- a/docker/Dockerfile.aws.lambda +++ b/docker/Dockerfile.aws.lambda @@ -6,10 +6,6 @@ COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.8.1 /lambda-adapter /opt # Copy nltk_lambda_layer for using nltk in lambda COPY --from=petercatai/nltk-layer:1.0.1 /nltk_data /opt/nltk_data -# 安装 libmagic -RUN apt-get update && \ - apt-get install -y --no-install-recommends libmagic1 - # Copy function code COPY . ${LAMBDA_TASK_ROOT} # from your project folder. diff --git a/server/aws/router.py b/server/aws/router.py index cb0b4523..48a1d9b0 100644 --- a/server/aws/router.py +++ b/server/aws/router.py @@ -6,7 +6,6 @@ from .schemas import ImageMetaData from .dependencies import get_s3_client from .service import upload_image_to_s3 -import magic ALLOWED_MIME_TYPES = {"image/jpeg", "image/png", "image/gif", "image/webp"} @@ -17,13 +16,6 @@ responses={404: {"description": "Not found"}}, ) - -def is_allowed_file(file: UploadFile) -> bool: - mime = magic.Magic(mime=True) - mime_type = mime.from_buffer(file.file.read(2048)) - file.file.seek(0) # 重新定位到文件开头 - return mime_type in ALLOWED_MIME_TYPES - @router.post("/upload") async def upload_image( file: UploadFile = File(...), @@ -36,9 +28,6 @@ async def upload_image( if user is None or user.anonymous: raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Need Login") - if not is_allowed_file(file): - raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid file type") - metadata = ImageMetaData(title=title, description=description) result = upload_image_to_s3(file, metadata, s3_client) return {"status": "success", "data": result} diff --git a/server/requirements.txt b/server/requirements.txt index a8c29df5..21845f6f 100644 --- a/server/requirements.txt +++ b/server/requirements.txt @@ -28,5 +28,4 @@ fastapi_auth0 requests pytest httpx -python-magic petercat_utils>=0.1.31 \ No newline at end of file