feat(01-04): add StorageBackend ABC + MinIOBackend + factory
- backend/storage/base.py: StorageBackend ABC with 5 abstract methods mirroring ai/base.py
- backend/storage/minio_backend.py: MinIOBackend wrapping all sync Minio SDK calls in asyncio.to_thread(); STORE-02 key schema: {user_id}/{document_id}/{uuid4()}{ext}
- backend/storage/__init__.py: get_storage_backend() factory mirroring ai/__init__.py
- backend/tests/test_storage.py: remove xfail markers (plan 04 implements the module)
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
"""
|
||||
StorageBackend ABC for DocuVault.
|
||||
|
||||
Mirrors backend/ai/base.py — declares the abstract interface that all storage
|
||||
backends (MinIO, OneDrive, Google Drive, Nextcloud, WebDAV) must implement.
|
||||
|
||||
Five abstract methods define the contract:
|
||||
put_object — store bytes, return object key
|
||||
get_object — fetch bytes by key
|
||||
delete_object — remove object by key
|
||||
presigned_get_url — generate a time-limited download URL
|
||||
health_check — verify backend connectivity
|
||||
"""
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class StorageBackend(ABC):
|
||||
"""Abstract base class for DocuVault object storage backends."""
|
||||
|
||||
@abstractmethod
|
||||
async def put_object(
|
||||
self,
|
||||
user_id: str,
|
||||
document_id: str,
|
||||
file_bytes: bytes,
|
||||
extension: str,
|
||||
content_type: str,
|
||||
) -> str:
|
||||
"""Store bytes and return the generated object key.
|
||||
|
||||
The key MUST follow the STORE-02 schema: {user_id}/{document_id}/{uuid4()}{ext}.
|
||||
The human-readable filename MUST NOT appear in the returned key.
|
||||
"""
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
async def get_object(self, object_key: str) -> bytes:
|
||||
"""Fetch object bytes by key. Raises on missing key."""
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
async def delete_object(self, object_key: str) -> None:
|
||||
"""Delete an object by key. No-op if the key does not exist."""
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
async def presigned_get_url(self, object_key: str, expires_minutes: int = 60) -> str:
|
||||
"""Return a time-limited pre-signed download URL for the object."""
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
async def health_check(self) -> bool:
|
||||
"""Return True if the backend is reachable and operational."""
|
||||
...
|
||||
Reference in New Issue
Block a user