@engine9-io/input-tools 1.9.7 → 1.9.9

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.
@@ -734,7 +734,7 @@ Worker.prototype.listAll = async function ({ directory, start: s, end: e }) {
734
734
  if (e) end = relativeDate(e).getTime();
735
735
  if (directory.startsWith('s3://') || directory.startsWith('r2://')) {
736
736
  const worker = new (directory.startsWith('r2://') ? R2Worker : S3Worker)(this);
737
- return worker.listAll({ directory });
737
+ return worker.listAll({ directory, start, end });
738
738
  }
739
739
  const a = await fsp.readdir(directory, { recursive: true });
740
740
 
@@ -769,9 +769,12 @@ Worker.prototype.listAll = async function ({ directory, start: s, end: e }) {
769
769
  };
770
770
  Worker.prototype.listAll.metadata = {
771
771
  options: {
772
- directory: { required: true }
772
+ directory: { required: true },
773
+ start: {},
774
+ end: {}
773
775
  }
774
776
  };
777
+
775
778
  Worker.prototype.moveAll = async function (options) {
776
779
  const { directory, targetDirectory } = options;
777
780
  if (!directory) throw new Error('directory is required');
@@ -821,6 +824,23 @@ Worker.prototype.empty.metadata = {
821
824
  }
822
825
  };
823
826
 
827
+ Worker.prototype.removeAll = async function (options) {
828
+ const filenames = await this.listAll(options);
829
+
830
+ const pLimit = await import('p-limit');
831
+
832
+ const limitedMethod = pLimit.default(10);
833
+
834
+ return Promise.all(filenames.map((filename) => limitedMethod(async () => this.remove({ filename }))));
835
+ };
836
+ Worker.prototype.removeAll.metadata = {
837
+ options: {
838
+ directory: { required: true },
839
+ start: {},
840
+ end: {}
841
+ }
842
+ };
843
+
824
844
  Worker.prototype.remove = async function ({ filename }) {
825
845
  if (!filename) throw new Error('filename is required');
826
846
  if (typeof filename !== 'string') throw new Error(`filename isn't a string:${JSON.stringify(filename)}`);
@@ -878,7 +898,7 @@ Worker.prototype.move = async function ({ filename, target, remove = true }) {
878
898
  await fsp.rename(filename, target);
879
899
  } catch (e) {
880
900
  //it may be a filesystem issue moving between items
881
- debug(e);
901
+ debug('Assuming this is a filesystem crosslink error, ignoring ', e.getMessage());
882
902
  await fsp.copyFile(filename, target);
883
903
  await fsp.unlink(filename);
884
904
  }
package/file/S3.js CHANGED
@@ -11,7 +11,7 @@ const {
11
11
  PutObjectCommand,
12
12
  ListObjectsV2Command
13
13
  } = require('@aws-sdk/client-s3');
14
- const { getTempFilename } = require('./tools');
14
+ const { getTempFilename, relativeDate } = require('./tools');
15
15
 
16
16
  function Worker() {
17
17
  this.prefix = 's3';
@@ -261,9 +261,12 @@ Worker.prototype.list.metadata = {
261
261
  }
262
262
  };
263
263
  /* List everything with the prefix */
264
- Worker.prototype.listAll = async function ({ directory }) {
264
+ Worker.prototype.listAll = async function (options) {
265
+ const { directory } = options;
265
266
  if (!directory) throw new Error('directory is required');
266
267
  let dir = directory;
268
+ const start = options.start && relativeDate(options.start);
269
+ const end = options.end && relativeDate(options.end);
267
270
  while (dir.slice(-1) === '/') dir = dir.slice(0, -1);
268
271
  const { Bucket, Key } = getParts(dir);
269
272
  const s3Client = this.getClient();
@@ -281,7 +284,16 @@ Worker.prototype.listAll = async function ({ directory }) {
281
284
  debug(`Sending List command with prefix ${Prefix} with ContinuationToken ${ContinuationToken}`);
282
285
 
283
286
  const result = await s3Client.send(command);
284
- const newFiles = result.Contents?.map((d) => `${this.prefix}://${Bucket}/${d.Key}`) || [];
287
+ const newFiles =
288
+ result.Contents?.filter(({ LastModified }) => {
289
+ if (start && new Date(LastModified) < start) {
290
+ return false;
291
+ } else if (end && new Date(LastModified) > end) {
292
+ return false;
293
+ } else {
294
+ return true;
295
+ }
296
+ })?.map((d) => `${this.prefix}://${Bucket}/${d.Key}`) || [];
285
297
  debug(`Retrieved ${newFiles.length} new files, total ${files.length},sample ${newFiles.slice(0, 3).join(',')}`);
286
298
  files.push(...newFiles);
287
299
  ContinuationToken = result.NextContinuationToken;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engine9-io/input-tools",
3
- "version": "1.9.7",
3
+ "version": "1.9.9",
4
4
  "description": "Tools for dealing with Engine9 inputs",
5
5
  "main": "index.js",
6
6
  "scripts": {