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
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions packages/file-storage/src/lib/file-storage-s3.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ function config(setup: FileStorageS3Setup) {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const loaderFn = (): { S3: typeof import('@aws-sdk/client-s3').S3 } => require('@aws-sdk/client-s3');
const { S3 } = loadPackage('@aws-sdk/client-s3', FileStorageS3.name, loaderFn);

const s3 = new S3({
/**
* We cannot really make calls without credentials unless we use a workaround
* @see https://github.com/aws/aws-sdk-js-v3/issues/2321
*/
...(credentials ? { credentials } : {}),
region,
// Add endpoint configuration for DigitalOcean Spaces and other S3-compatible services
...(endpoint
? {
endpoint,
forcePathStyle: false, // Use virtual-hosted-style URLs (required for DigitalOcean Spaces)
}
: {}),
...(logger ? { logger } : {}),
});

Expand Down Expand Up @@ -71,8 +79,19 @@ export class FileStorageS3 implements FileStorage {
}

static extractRegionFromEndpoint(endpoint: string): string | null {
const match = endpoint?.match(/(?<=\.)[^.]+(?=\.amazonaws\.com)/);
return match?.length ? match[0] : null;
// Handle AWS S3 endpoints
const awsMatch = endpoint?.match(/(?<=\.)[^.]+(?=\.amazonaws\.com)/);
if (awsMatch?.length) {
return awsMatch[0];
}

// Handle DigitalOcean Spaces endpoints (e.g., nyc3.digitaloceanspaces.com)
const doMatch = endpoint?.match(/^https?:\/\/([^.]+)\.digitaloceanspaces\.com/);
if (doMatch && doMatch?.length > 1) {
return doMatch[1];
}

return null;
}

transformFilePath(
Expand Down