Rename MinIO config to S3, switch to Cloudflare R2

- Rename MinioConfig → S3Config, settings.minio → settings.s3
- Update config.example.yaml with R2 endpoint template
- S3 service is now storage-backend agnostic (MinIO, R2, any S3-compatible)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-05-28 13:43:10 +08:00
parent c9f7f55d81
commit 2d7c8a6f3f
3 changed files with 15 additions and 15 deletions

View File

@@ -4,7 +4,7 @@ import yaml
from pydantic import BaseModel
class MinioConfig(BaseModel):
class S3Config(BaseModel):
endpoint: str
public_endpoint: str = ""
bucket: str = "snapledger"
@@ -32,7 +32,7 @@ class ApiConfig(BaseModel):
class AppConfig(BaseModel):
minio: MinioConfig
s3: S3Config
postgresql: PostgresConfig
api: ApiConfig

View File

@@ -11,9 +11,9 @@ from app.config import settings
def _get_client():
return boto3.client(
"s3",
endpoint_url=settings.minio.endpoint,
aws_access_key_id=settings.minio.access_key,
aws_secret_access_key=settings.minio.secret_key,
endpoint_url=settings.s3.endpoint,
aws_access_key_id=settings.s3.access_key,
aws_secret_access_key=settings.s3.secret_key,
config=BotoConfig(signature_version="s3v4"),
)
@@ -33,7 +33,7 @@ def upload_image(file_bytes: bytes, original_filename: str) -> str:
content_type = "image/png"
client.put_object(
Bucket=settings.minio.bucket,
Bucket=settings.s3.bucket,
Key=object_key,
Body=file_bytes,
ContentType=content_type,
@@ -43,12 +43,12 @@ def upload_image(file_bytes: bytes, original_filename: str) -> str:
def _get_presign_client():
"""Client using public endpoint so presigned URL signatures match the public host."""
endpoint = settings.minio.public_endpoint or settings.minio.endpoint
endpoint = settings.s3.public_endpoint or settings.s3.endpoint
return boto3.client(
"s3",
endpoint_url=endpoint,
aws_access_key_id=settings.minio.access_key,
aws_secret_access_key=settings.minio.secret_key,
aws_access_key_id=settings.s3.access_key,
aws_secret_access_key=settings.s3.secret_key,
config=BotoConfig(signature_version="s3v4"),
)
@@ -58,7 +58,7 @@ def generate_presigned_put_url(object_key: str) -> str:
url: str = client.generate_presigned_url(
"put_object",
Params={
"Bucket": settings.minio.bucket,
"Bucket": settings.s3.bucket,
"Key": object_key,
},
ExpiresIn=300,

View File

@@ -1,12 +1,12 @@
# SnapLedger Backend Configuration
# Copy this file to config.yaml and fill in your credentials.
minio:
endpoint: "https://minio.example.com:9000"
public_endpoint: "https://minio-public.example.com"
s3:
endpoint: "https://<account-id>.r2.cloudflarestorage.com"
public_endpoint: ""
bucket: "snapledger"
access_key: "YOUR_MINIO_ACCESS_KEY"
secret_key: "YOUR_MINIO_SECRET_KEY"
access_key: "YOUR_S3_ACCESS_KEY"
secret_key: "YOUR_S3_SECRET_KEY"
postgresql:
host: "localhost"