mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 17:30:16 +01:00
Merge e28e9969fa into b288d81f5a
This commit is contained in:
commit
39c682ce9d
2 changed files with 17 additions and 0 deletions
|
|
@ -11,8 +11,10 @@ const {
|
||||||
DeleteObjectCommand,
|
DeleteObjectCommand,
|
||||||
} = require('@aws-sdk/client-s3');
|
} = require('@aws-sdk/client-s3');
|
||||||
|
|
||||||
|
const endpoint = process.env.AWS_ENDPOINT_URL;
|
||||||
const bucketName = process.env.AWS_BUCKET_NAME;
|
const bucketName = process.env.AWS_BUCKET_NAME;
|
||||||
const defaultBasePath = 'images';
|
const defaultBasePath = 'images';
|
||||||
|
const forcePathStyle = ['1', 'true', 'yes'].includes(process.env.AWS_FORCE_PATH_STYLE?.toLowerCase());
|
||||||
|
|
||||||
let s3UrlExpirySeconds = 2 * 60; // 2 minutes
|
let s3UrlExpirySeconds = 2 * 60; // 2 minutes
|
||||||
let s3RefreshExpiryMs = null;
|
let s3RefreshExpiryMs = null;
|
||||||
|
|
@ -250,6 +252,13 @@ function extractKeyFromS3Url(fileUrlOrKey) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const url = new URL(fileUrlOrKey);
|
const url = new URL(fileUrlOrKey);
|
||||||
|
|
||||||
|
if (endpoint?.trim() && forcePathStyle) {
|
||||||
|
const endpointUrl = new URL(endpoint)
|
||||||
|
const startPos = endpointUrl.pathname.length + (endpointUrl.pathname.endsWith('/') ? 2 : 1) + bucketName.length + 1;
|
||||||
|
return url.pathname.substring(startPos);
|
||||||
|
}
|
||||||
|
|
||||||
return url.pathname.substring(1);
|
return url.pathname.substring(1);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const parts = fileUrlOrKey.split('/');
|
const parts = fileUrlOrKey.split('/');
|
||||||
|
|
@ -258,6 +267,12 @@ function extractKeyFromS3Url(fileUrlOrKey) {
|
||||||
return fileUrlOrKey;
|
return fileUrlOrKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (endpoint?.trim() && forcePathStyle) {
|
||||||
|
const endpointUrl = new URL(endpoint)
|
||||||
|
const startPos = endpointUrl.pathname.length + (endpointUrl.pathname.endsWith('/') ? 2 : 1) + bucketName.length + 1;
|
||||||
|
return fileUrlOrKey.substring(startPos);
|
||||||
|
}
|
||||||
|
|
||||||
return fileUrlOrKey.startsWith('/') ? fileUrlOrKey.substring(1) : fileUrlOrKey;
|
return fileUrlOrKey.startsWith('/') ? fileUrlOrKey.substring(1) : fileUrlOrKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,11 @@ export const initializeS3 = (): S3Client | null => {
|
||||||
const endpoint = process.env.AWS_ENDPOINT_URL;
|
const endpoint = process.env.AWS_ENDPOINT_URL;
|
||||||
const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
|
const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
|
||||||
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
|
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
|
||||||
|
const forcePathStyle = ['1', 'true', 'yes'].includes(process.env.AWS_FORCE_PATH_STYLE?.toLowerCase());
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
region,
|
region,
|
||||||
|
forcePathStyle: forcePathStyle, // Enable path-style addressing
|
||||||
// Conditionally add the endpoint if it is provided
|
// Conditionally add the endpoint if it is provided
|
||||||
...(endpoint ? { endpoint } : {}),
|
...(endpoint ? { endpoint } : {}),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue