| | import { S3Client } from '@aws-sdk/client-s3'; |
| | import { logger } from '@librechat/data-schemas'; |
| |
|
| | let s3: S3Client | null = null; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | export const initializeS3 = (): S3Client | null => { |
| | if (s3) { |
| | return s3; |
| | } |
| |
|
| | const region = process.env.AWS_REGION; |
| | if (!region) { |
| | logger.error('[initializeS3] AWS_REGION is not set. Cannot initialize S3.'); |
| | return null; |
| | } |
| |
|
| | |
| | const endpoint = process.env.AWS_ENDPOINT_URL; |
| | const accessKeyId = process.env.AWS_ACCESS_KEY_ID; |
| | const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY; |
| |
|
| | const config = { |
| | region, |
| | |
| | ...(endpoint ? { endpoint } : {}), |
| | }; |
| |
|
| | if (accessKeyId && secretAccessKey) { |
| | s3 = new S3Client({ |
| | ...config, |
| | credentials: { accessKeyId, secretAccessKey }, |
| | }); |
| | logger.info('[initializeS3] S3 initialized with provided credentials.'); |
| | } else { |
| | |
| | s3 = new S3Client(config); |
| | logger.info('[initializeS3] S3 initialized using default credentials (IRSA).'); |
| | } |
| |
|
| | return s3; |
| | }; |
| |
|