Skip to content

Commit b5dfda2

Browse files
authored
Merge branch 'master' into snyk-upgrade-b755cab69bb0e56a63305eaa4b2f9787
2 parents 8f7791d + fd8d3b9 commit b5dfda2

File tree

6 files changed

+51
-10
lines changed

6 files changed

+51
-10
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# [4.2.0](https://github.com/parse-community/parse-server-s3-adapter/compare/4.1.1...4.2.0) (2025-06-12)
2+
3+
4+
### Features
5+
6+
* Add support for option `baseUrl` set to async function ([#285](https://github.com/parse-community/parse-server-s3-adapter/issues/285)) ([6eae9e1](https://github.com/parse-community/parse-server-s3-adapter/commit/6eae9e1f4f4e496e4a53983464639e6d2a303f93))
7+
18
## [4.1.1](https://github.com/parse-community/parse-server-s3-adapter/compare/4.1.0...4.1.1) (2025-06-04)
29

310

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ The preferred method is to use the default AWS credentials pattern. If no AWS c
126126
"bucketPrefix": '', // default value
127127
"directAccess": false, // default value
128128
"fileAcl": null, // default value
129-
"baseUrl": null, // default value
129+
"baseUrl": null, // string, function or async function
130130
"baseUrlDirect": false, // default value
131131
"signatureVersion": 'v4', // default value
132132
"globalCacheControl": null, // default value. Or 'public, max-age=86400' for 24 hrs Cache-Control
@@ -227,7 +227,7 @@ var s3Options = {
227227
"region": 'us-east-1', // default value
228228
"bucketPrefix": '', // default value
229229
"directAccess": false, // default value
230-
"baseUrl": null // default value
230+
"baseUrl": null // string, function or async function
231231
"signatureVersion": 'v4', // default value
232232
"globalCacheControl": null, // default value. Or 'public, max-age=86400' for 24 hrs Cache-Control
233233
"presignedUrl": false, // default value

index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ const serialize = obj => {
3131
return str.join('&');
3232
};
3333

34-
function buildDirectAccessUrl(baseUrl, baseUrlFileKey, presignedUrl, config, filename) {
35-
let directAccessUrl;
34+
async function buildDirectAccessUrl(baseUrl, baseUrlFileKey, presignedUrl, config, filename) {
35+
let urlBase;
3636
if (typeof baseUrl === 'function') {
37-
directAccessUrl = `${baseUrl(config, filename)}/${baseUrlFileKey}`;
37+
urlBase = await baseUrl(config, filename);
3838
} else {
39-
directAccessUrl = `${baseUrl}/${baseUrlFileKey}`;
39+
urlBase = baseUrl;
4040
}
41+
let directAccessUrl = `${urlBase}/${baseUrlFileKey}`;
4142

4243
if (presignedUrl) {
4344
directAccessUrl += presignedUrl.substring(presignedUrl.indexOf('?'));
@@ -246,7 +247,7 @@ class S3Adapter {
246247
}
247248

248249
const baseUrlFileKey = this._baseUrlDirect ? fileName : fileKey;
249-
return buildDirectAccessUrl(this._baseUrl, baseUrlFileKey, presignedUrl, config, filename);
250+
return await buildDirectAccessUrl(this._baseUrl, baseUrlFileKey, presignedUrl, config, filename);
250251
}
251252

252253
async handleFileStream(filename, req, res) {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@parse/s3-files-adapter",
3-
"version": "4.1.1",
3+
"version": "4.2.0",
44
"description": "AWS S3 adapter for parse-server",
55
"main": "index.js",
66
"repository": {

spec/test.spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,39 @@ describe('S3Adapter tests', () => {
640640
});
641641
});
642642

643+
describe('getFileLocation with async baseUrl', () => {
644+
const testConfig = {
645+
mount: 'http://example.com/parse',
646+
applicationId: 'xxxx',
647+
};
648+
let options;
649+
650+
beforeEach(() => {
651+
options = {
652+
directAccess: true,
653+
bucketPrefix: 'foo/bar/',
654+
baseUrl: async () => {
655+
return await Promise.resolve('http://example.com/files');
656+
},
657+
};
658+
});
659+
660+
it('should await async baseUrl', async () => {
661+
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
662+
await expectAsync(s3.getFileLocation(testConfig, 'test.png')).toBeResolvedTo(
663+
'http://example.com/files/foo/bar/test.png'
664+
);
665+
});
666+
667+
it('should direct to async baseUrl when baseUrlDirect', async () => {
668+
options.baseUrlDirect = true;
669+
const s3 = new S3Adapter('accessKey', 'secretKey', 'my-bucket', options);
670+
await expectAsync(s3.getFileLocation(testConfig, 'test.png')).toBeResolvedTo(
671+
'http://example.com/files/test.png'
672+
);
673+
});
674+
});
675+
643676
describe('validateFilename', () => {
644677
let options;
645678

0 commit comments

Comments
 (0)