-
Notifications
You must be signed in to change notification settings - Fork 66
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
support s3 directories with more than 1000 keys #315
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -40,39 +40,58 @@ function createS3Service(config: Object) { | |||||
format: null | ||||||
}); | ||||||
const listObjects = (path: string, callback: Function) => { | ||||||
const params = { | ||||||
var params = { | ||||||
Prefix: s3Prefix(path), | ||||||
Delimiter: config.s3PathDelimiter, // Maximum allowed by S3 API | ||||||
MaxKeys: 2147483647, //remove the folder name from listing | ||||||
StartAfter: s3Prefix(path) | ||||||
}; | ||||||
s3.listObjectsV2(params, (err, data) => { | ||||||
if (err || !data) { | ||||||
callback(err); | ||||||
return; | ||||||
} | ||||||
if (!data.Contents) { | ||||||
callback(new Error("Missing contents from S3 Response")); | ||||||
return; | ||||||
} | ||||||
if (!data.CommonPrefixes) { | ||||||
callback(new Error("Missing CommonPrefixes from S3 Response")); | ||||||
return; | ||||||
} | ||||||
const files = data.Contents.map(fileObject); | ||||||
const dirs = data.CommonPrefixes.map(dirObject); | ||||||
callback(null, { | ||||||
name: fileName(path), | ||||||
path: path, | ||||||
type: "directory", | ||||||
writable: true, | ||||||
created: null, | ||||||
last_modified: null, | ||||||
mimetype: null, | ||||||
content: [...files, ...dirs], | ||||||
format: "json" | ||||||
var files = []; | ||||||
var dirs = []; | ||||||
function listAllKeys(cb) { | ||||||
s3.listObjectsV2(params, (err, data) => { | ||||||
if (err || !data) { | ||||||
cb(err); | ||||||
return; | ||||||
} | ||||||
if (!data.Contents) { | ||||||
cb(new Error("Missing contents from S3 Response")); | ||||||
return; | ||||||
} | ||||||
if (!data.CommonPrefixes) { | ||||||
cb(new Error("Missing CommonPrefixes from S3 Response")); | ||||||
return; | ||||||
} | ||||||
else { | ||||||
var contents = data.Contents; | ||||||
var prefixes = data.CommonPrefixes; | ||||||
contents.forEach(content => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason for not using |
||||||
files.push(fileObject(content)); | ||||||
}); | ||||||
prefixes.forEach(content => { | ||||||
dirs.push(dirObject(content)); | ||||||
}); | ||||||
|
||||||
if (data.IsTruncated) { | ||||||
params.ContinuationToken = data.NextContinuationToken; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||||||
listAllKeys(cb); | ||||||
return | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
cb(null, { | ||||||
name: fileName(path), | ||||||
path: path, | ||||||
type: "directory", | ||||||
writable: true, | ||||||
created: null, | ||||||
last_modified: null, | ||||||
mimetype: null, | ||||||
content: [...files, ...dirs], | ||||||
format: "json" | ||||||
}); | ||||||
}); | ||||||
}); | ||||||
} | ||||||
listAllKeys(callback); | ||||||
}; | ||||||
const getObject = (path: string, callback: Function) => { | ||||||
s3.getObject({ Key: s3Prefix(path) }, (err, data) => { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the
else
here is necessary. Once we've completed the null checks on theCommonPrefixes
,Contents
, anddata
then we'll always do the processing below.