From 2d7c8a6f3f95d743d90f4e81ea8782a926dc5ebc Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Thu, 28 May 2026 13:43:10 +0800 Subject: [PATCH] Rename MinIO config to S3, switch to Cloudflare R2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- app/config.py | 4 ++-- app/services/minio.py | 16 ++++++++-------- config.example.yaml | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/config.py b/app/config.py index 36048a6..adb40bf 100644 --- a/app/config.py +++ b/app/config.py @@ -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 diff --git a/app/services/minio.py b/app/services/minio.py index e16e0bc..898b612 100644 --- a/app/services/minio.py +++ b/app/services/minio.py @@ -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, diff --git a/config.example.yaml b/config.example.yaml index 9a30bd8..79ac0e4 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -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://.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"