Skip to content

Commit

Permalink
feat: revert upload detect (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
RaoHai authored Sep 4, 2024
1 parent 6fcf2ed commit 502ca3e
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 21 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions docker/Dockerfile.aws.lambda
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 0 additions & 11 deletions server/aws/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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(...),
Expand All @@ -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}
1 change: 0 additions & 1 deletion server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ fastapi_auth0
requests
pytest
httpx
python-magic
petercat_utils>=0.1.31

0 comments on commit 502ca3e

Please sign in to comment.