Skip to content

Commit

Permalink
feat: enhance file upload configuration for MinIO support
Browse files Browse the repository at this point in the history
  • Loading branch information
minai621 committed Nov 5, 2024
1 parent 5b289fa commit 7543c98
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
1 change: 1 addition & 0 deletions backend/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ LANGCHAIN_API_KEY=your_langsmith_api_key_here
LANGCHAIN_PROJECT=your_langsmith_project_name_here

# FILE_UPLOAD: Whether to enable file upload to storage
# Available options: false, s3, minio
# If set to false, AWS_S3_BUCKET_NAME is not required.
# Set to true if file upload is required.
FILE_UPLOAD=false
Expand Down
11 changes: 6 additions & 5 deletions backend/docker/docker-compose-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ services:
LANGCHAIN_API_KEY: "your_langsmith_api_key_here"
LANGCHAIN_PROJECT: "your_langsmith_project_name_here"
FILE_UPLOAD: false
BUCKET_TYPE: "S3 or MINIO"
BUCKET_NAME: "your_s3_bucket_name_here"
MINIO_ENDPOINT: "your_minio_endpoint_here"
MINIO_ACCESS_KEY: "your_minio_access_key_here"
MINIO_SECRET_KEY: "your_minio_secret_key_here"
AWS_REGION: "your_aws_region_here"
# Default configuration values for using Minio
BUCKET_NAME: "default-storage"
MINIO_ENDPOINT: "http://localhost:9000"
STORAGE_ACCESS_KEY: "minioadmin"
STORAGE_SECRET_KEY: "minioadmin"
ports:
- "3000:3000"
depends_on:
Expand Down
26 changes: 12 additions & 14 deletions backend/src/storage/storage.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ConfigService } from "@nestjs/config";
const s3ClientFactory = {
provide: "STORAGE_CLIENT",
useFactory: (configService: ConfigService): S3Client | null => {
const fileUpload = configService.get<boolean>("FILE_UPLOAD");
const fileUpload = configService.get<boolean | "s3" | "minio">("FILE_UPLOAD");
if (!fileUpload) {
return null;
}
Expand All @@ -14,19 +14,17 @@ const s3ClientFactory = {
const accessKeyId = configService.get<string>("STORAGE_ACCESS_KEY");
const secretAccessKey = configService.get<string>("STORAGE_SECRET_KEY");

const config: S3ClientConfig = fileUpload
? {
region,
endpoint,
forcePathStyle: true,
credentials: {
accessKeyId,
secretAccessKey,
},
}
: {
region,
};
const config: S3ClientConfig = {
region,
...(fileUpload === "minio" && {
endpoint,
forcePathStyle: true,
credentials: {
accessKeyId,
secretAccessKey,
},
}),
};

return new S3Client(config);
},
Expand Down

0 comments on commit 7543c98

Please sign in to comment.