-
-
Notifications
You must be signed in to change notification settings - Fork 88
feat: Revise createFile logic to return modified filenames and location #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AdrianCurtin
wants to merge
19
commits into
parse-community:master
Choose a base branch
from
AdrianCurtin:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3172564
Revise createFile logic to preserve key & location
AdrianCurtin be61240
Change to name to be consistent with parse server createFile
AdrianCurtin d8c1e15
Update test.spec.js
AdrianCurtin f3f685b
Update index.js
AdrianCurtin fb9c42e
Correction to make codecov happy
AdrianCurtin 394e175
Remove and add some spaces to make lint happy
AdrianCurtin 9d760be
Allow generate key to access certain createfile traits
AdrianCurtin 84e11a5
Add tests for url when config is provided and error on generatekey
AdrianCurtin 7afb0a2
Change spaces and adjust tests
AdrianCurtin f5616d9
Also mock s3 response for good measure
AdrianCurtin 3ba5566
Remove another two spaces + change liboptions error back to quotes
AdrianCurtin 227c7cf
Revise config check and don't throw error response to prevent leaking…
AdrianCurtin 6a3b0cf
Directly run generate key to preserve error trace
AdrianCurtin b7d124f
Remove s3_response & specifically check config for needed vars
AdrianCurtin bf88785
Allow async key generation and revise test
AdrianCurtin 2cac314
trim & test key after generation & assmble endpoint accordingly
AdrianCurtin c78165a
Fix trailing spaces
AdrianCurtin d87fc64
Merge branch 'master' into master
mtrezza 05a056a
Change from snake case
AdrianCurtin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,16 +140,19 @@ class S3Adapter { | |
|
||
// For a given config object, filename, and data, store a file in S3 | ||
// Returns a promise containing the S3 object creation response | ||
async createFile(filename, data, contentType, options = {}) { | ||
async createFile(filename, data, contentType, options = {}, config = {}) { | ||
|
||
let key_without_prefix = filename; | ||
if (this._generateKey instanceof Function) { | ||
key_without_prefix = this._generateKey(filename, contentType, options); | ||
} | ||
|
||
const params = { | ||
Bucket: this._bucket, | ||
Key: this._bucketPrefix + filename, | ||
Key: this._bucketPrefix + key_without_prefix, | ||
Body: data, | ||
}; | ||
|
||
if (this._generateKey instanceof Function) { | ||
params.Key = this._bucketPrefix + this._generateKey(filename); | ||
} | ||
if (this._fileAcl) { | ||
if (this._fileAcl === 'none') { | ||
delete params.ACL; | ||
|
@@ -181,7 +184,17 @@ class S3Adapter { | |
const endpoint = this._endpoint || `https://${this._bucket}.s3.${this._region}.amazonaws.com`; | ||
const location = `${endpoint}/${params.Key}`; | ||
|
||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
return Object.assign(response || {}, { Location: location }); | ||
let url; | ||
if (config && typeof config === 'object' && Object.keys(config).length > 0) { // if config is passed, we can generate a presigned url here | ||
url = await this.getFileLocation(config, key_without_prefix); | ||
} | ||
|
||
return { | ||
location: location, // actual upload location, used for tests | ||
name: key_without_prefix, // filename in storage, consistent with other adapters | ||
s3_response: response, // raw s3 response | ||
|
||
...url ? { url: url } : {} // url (optionally presigned) or non-direct access url | ||
}; | ||
} | ||
|
||
async deleteFile(filename) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.