diff --git a/app/main.py b/app/main.py index 6f6a2e6..472e0ec 100644 --- a/app/main.py +++ b/app/main.py @@ -2,7 +2,6 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.openapi.utils import get_openapi from app.routers import documents -from app.config import settings from app.logger import setup_logging from app.middleware.auth import AuthMiddleware diff --git a/app/middleware/auth.py b/app/middleware/auth.py index c2bf9ef..498391d 100644 --- a/app/middleware/auth.py +++ b/app/middleware/auth.py @@ -1,6 +1,5 @@ from fastapi import Request from starlette.middleware.base import BaseHTTPMiddleware -from starlette.responses import JSONResponse from app.logger import get_logger logger = get_logger(__name__) diff --git a/app/models.py b/app/models.py index d0e3442..8edf1f6 100644 --- a/app/models.py +++ b/app/models.py @@ -1,6 +1,5 @@ from pydantic import BaseModel, Field from datetime import datetime -from typing import Optional from app.enums import DocumentType class DocumentMetadata(BaseModel): diff --git a/app/pdf.py b/app/pdf.py index 8db0e1d..94c92b2 100644 --- a/app/pdf.py +++ b/app/pdf.py @@ -1,6 +1,4 @@ -import os from pypdf import PdfReader -from typing import Any def discover_fields(pdf_path: str) -> list[dict]: """ diff --git a/app/routers/__init__.py b/app/routers/__init__.py index 136140f..a770ded 100644 --- a/app/routers/__init__.py +++ b/app/routers/__init__.py @@ -1 +1,3 @@ -from app.routers import documents +from app.routers import documents as documents + +__all__ = ["documents"] diff --git a/app/routers/documents.py b/app/routers/documents.py index 16b2a24..5549c65 100644 --- a/app/routers/documents.py +++ b/app/routers/documents.py @@ -1,6 +1,5 @@ import os -from fastapi import APIRouter, HTTPException, UploadFile, File, Form, Request -from typing import Optional +from fastapi import APIRouter, HTTPException, UploadFile, File, Request from datetime import datetime from app import s3, pdf, utils diff --git a/app/s3.py b/app/s3.py index 6752dd1..3f42bd3 100644 --- a/app/s3.py +++ b/app/s3.py @@ -49,16 +49,25 @@ def ensure_bucket_exists() -> None: def upload_file(file: UploadFile, s3_key: str, content_type: str, metadata: dict = None) -> str: """Upload file to S3 with metadata""" client = get_client() - + + # Read file content + file.file.seek(0, os.SEEK_END) + file_size = file.file.tell() + file.file.seek(0) + file_content = file.file.read() + file.file.seek(0) + extra_args = {"ContentType": content_type} if metadata: extra_args["Metadata"] = metadata - - client.upload_fileobj( - file.file, - settings.s3_bucket, - s3_key, - ExtraArgs=extra_args + + client.put_object( + Bucket=settings.s3_bucket, + Key=s3_key, + Body=file_content, + ContentLength=file_size, + ContentType=content_type, + Metadata=metadata ) return s3_key diff --git a/ops/chart/values.yaml b/ops/chart/values.yaml index 92411f8..4bb6166 100644 --- a/ops/chart/values.yaml +++ b/ops/chart/values.yaml @@ -56,3 +56,15 @@ service: port: 8082 protocol: HTTP +rawResources: + document-service-bucket: + enabled: true + apiVersion: objectstorage.k8s.io/v1alpha1 + kind: BucketClaim + suffix: bucket + spec: + spec: + bucketClassName: seaweedfs + protocols: + - s3 +