eip-cloud-services 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/s3.js +39 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eip-cloud-services",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Houses a collection of helpers for connecting with Cloud services.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,4 +23,4 @@
|
|
|
23
23
|
"mysql": "^2.18.1",
|
|
24
24
|
"redis": "^4.6.7"
|
|
25
25
|
}
|
|
26
|
-
}
|
|
26
|
+
}
|
package/src/s3.js
CHANGED
|
@@ -326,6 +326,45 @@ exports.move = async ( sourceKey, destinationKey, sourceBucket = config?.s3?.Buc
|
|
|
326
326
|
}
|
|
327
327
|
};
|
|
328
328
|
|
|
329
|
+
/**
|
|
330
|
+
* List objects in an S3 bucket filtered by a prefix, with support for pagination.
|
|
331
|
+
*
|
|
332
|
+
* @param {string} prefix - The prefix to filter objects by.
|
|
333
|
+
* @param {string} [bucket=config?.s3?.Bucket] - The bucket name. Defaults to the configured bucket.
|
|
334
|
+
* @param {string} [continuationToken] - The continuation token for pagination (optional).
|
|
335
|
+
* @returns {Promise} A promise that resolves with the list of objects and potentially a continuation token for further pagination.
|
|
336
|
+
* @description Retrieves a list of objects from S3 that match the given prefix, with support for pagination.
|
|
337
|
+
*/
|
|
338
|
+
exports.listObjects = async ( prefix, bucket = config?.s3?.Bucket, continuationToken ) => {
|
|
339
|
+
try {
|
|
340
|
+
const params = {
|
|
341
|
+
Bucket: bucket,
|
|
342
|
+
Prefix: prefix,
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
if ( continuationToken ) {
|
|
346
|
+
params.ContinuationToken = continuationToken;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const command = new ListObjectsV2Command ( params );
|
|
350
|
+
|
|
351
|
+
const data = await S3.send ( command );
|
|
352
|
+
|
|
353
|
+
if ( config?.s3?.logs === 'outputs' || config?.s3?.logs === 'verbose' ) {
|
|
354
|
+
log ( `S3 [LIST]: Retrieved list for prefix ${prefix} on ${bucket}${continuationToken ? ' with continuation token' : ''}.` );
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return {
|
|
358
|
+
objects: data.Contents,
|
|
359
|
+
isTruncated: data.IsTruncated,
|
|
360
|
+
nextContinuationToken: data.NextContinuationToken,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
catch ( error ) {
|
|
364
|
+
throw error;
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
|
|
329
368
|
exports.getClient = S3;
|
|
330
369
|
|
|
331
370
|
const streamToBuffer = ( stream ) =>
|