- Default CORS_ORIGINS to http://localhost:5173 instead of "*" (still overridable) - Reject ".." and leading "/" in document keys/paths across get/save/delete/upload, mapped to HTTP 400 via new InvalidPathError - Add a delete button to DocumentEditor wired to deleteDocument + onDeleted, giving the existing DELETE API an actual UI entry point - Share a single lru_cache'd Meilisearch (and Minio) SDK client instance instead of constructing duplicates in dependencies.py - Add a startup check that creates the MinIO bucket if missing, tolerating MinIO being unreachable at boot without crashing the app
37 lines
1010 B
Python
37 lines
1010 B
Python
from functools import lru_cache
|
|
|
|
import meilisearch
|
|
from minio import Minio
|
|
|
|
from app.config import settings
|
|
from app.document_service import DocumentService
|
|
from app.minio_client import MinioClient
|
|
from app.search_client import SearchClient
|
|
|
|
|
|
@lru_cache
|
|
def _get_minio_sdk() -> Minio:
|
|
return Minio(
|
|
settings.minio_endpoint,
|
|
access_key=settings.minio_access_key,
|
|
secret_key=settings.minio_secret_key,
|
|
secure=False,
|
|
)
|
|
|
|
|
|
@lru_cache
|
|
def _get_meilisearch_sdk() -> meilisearch.Client:
|
|
return meilisearch.Client(settings.meilisearch_host, settings.meilisearch_api_key)
|
|
|
|
|
|
@lru_cache
|
|
def get_document_service() -> DocumentService:
|
|
minio_client = MinioClient(_get_minio_sdk(), settings.minio_bucket)
|
|
search_client = SearchClient(_get_meilisearch_sdk(), settings.meilisearch_index)
|
|
return DocumentService(minio_client, search_client)
|
|
|
|
|
|
@lru_cache
|
|
def get_search_client() -> SearchClient:
|
|
return SearchClient(_get_meilisearch_sdk(), settings.meilisearch_index)
|