Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions api/server/services/Files/S3/crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
DeleteObjectCommand,
} = require('@aws-sdk/client-s3');

const endpoint = process.env.AWS_ENDPOINT_URL;
const bucketName = process.env.AWS_BUCKET_NAME;
const defaultBasePath = 'images';
const forcePathStyle = ['1', 'true', 'yes'].includes(
(process.env.AWS_FORCE_PATH_STYLE ?? '').toLowerCase(),
);

let s3UrlExpirySeconds = 2 * 60; // 2 minutes
let s3RefreshExpiryMs = null;
Expand Down Expand Up @@ -252,8 +256,20 @@

try {
const url = new URL(fileUrlOrKey);

if (endpoint?.trim() && forcePathStyle) {
const endpointUrl = new URL(endpoint);
const startPos =
endpointUrl.pathname.length +
(endpointUrl.pathname.endsWith('/') ? 0 : 1) +
bucketName.length +
1;

return url.pathname.substring(startPos);
}

return url.pathname.substring(1);
} catch (error) {

Check warning on line 272 in api/server/services/Files/S3/crud.js

View workflow job for this annotation

GitHub Actions / Run ESLint Linting

'error' is defined but never used. Allowed unused caught errors must match /^_/u
const parts = fileUrlOrKey.split('/');

if (parts.length >= 3 && !fileUrlOrKey.startsWith('http') && !fileUrlOrKey.startsWith('/')) {
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/cdn/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ export const initializeS3 = (): S3Client | 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 forcePathStyle = ['1', 'true', 'yes'].includes(
(process.env.AWS_FORCE_PATH_STYLE ?? '').toLowerCase(),
);

const config = {
region,
forcePathStyle, // Conditionally enable path-style addressing
// Conditionally add the endpoint if it is provided
...(endpoint ? { endpoint } : {}),
};
Expand Down