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 47f41d1 commit d38b9d2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 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=true
Expand Down
2 changes: 1 addition & 1 deletion backend/docker/docker-compose-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
LANGCHAIN_TRACING_V2: "false"
LANGCHAIN_API_KEY: "your_langsmith_api_key_here"
LANGCHAIN_PROJECT: "your_langsmith_project_name_here"
FILE_UPLOAD: true
FILE_UPLOAD: false
AWS_REGION: "your_aws_region_here"
# Default configuration values for using Minio
BUCKET_NAME: "default-storage"
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 d38b9d2

Please sign in to comment.