@intecoag/inteco-cli 1.5.0 → 1.5.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intecoag/inteco-cli",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "CLI-Tools for Inteco",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -366,6 +366,7 @@ async function executeOperations(mode, operations) {
366
366
  const operation = operations[index];
367
367
  try {
368
368
  if (operation.type === "upload") {
369
+ const totalBytes = operation.localFile.size ?? null;
369
370
  spinner.text = `Uploading ${operation.localFile.relativePath} (${index + 1}/${operations.length})`;
370
371
  const md5Base64 = operation.localFile.md5Base64
371
372
  ?? await getLocalMd5Base64(operation.localFile.filePath);
@@ -373,15 +374,30 @@ async function executeOperations(mode, operations) {
373
374
  operation.containerClient,
374
375
  operation.localFile.blobPath,
375
376
  operation.localFile.filePath,
376
- md5Base64
377
+ md5Base64,
378
+ progress => {
379
+ if (!totalBytes) {
380
+ return;
381
+ }
382
+ const percent = ((progress.loadedBytes / totalBytes) * 100).toFixed(1);
383
+ spinner.text = `Uploading ${operation.localFile.relativePath} ${percent}% (${formatBytes(progress.loadedBytes)}/${formatBytes(totalBytes)})`;
384
+ }
377
385
  );
378
386
  } else if (operation.type === "download") {
387
+ const totalBytes = operation.localFile.size ?? null;
379
388
  spinner.text = `Downloading ${operation.localFile.relativePath} (${index + 1}/${operations.length})`;
380
389
  await ensureDirectory(path.dirname(operation.localFile.filePath));
381
390
  await operation.azure.downloadToFile(
382
391
  operation.containerClient,
383
392
  operation.localFile.blobPath,
384
- operation.localFile.filePath
393
+ operation.localFile.filePath,
394
+ progress => {
395
+ if (!totalBytes) {
396
+ return;
397
+ }
398
+ const percent = ((progress.loadedBytes / totalBytes) * 100).toFixed(1);
399
+ spinner.text = `Downloading ${operation.localFile.relativePath} ${percent}% (${formatBytes(progress.loadedBytes)}/${formatBytes(totalBytes)})`;
400
+ }
385
401
  );
386
402
  } else if (operation.type === "delete") {
387
403
  spinner.text = `Deleting ${operation.blobPath} (${index + 1}/${operations.length})`;
@@ -504,7 +520,8 @@ async function buildPullOperations(syncState, azure) {
504
520
  localFile: {
505
521
  filePath: localPath,
506
522
  relativePath: path.relative(entry.rootDir, localPath),
507
- blobPath: blob.name
523
+ blobPath: blob.name,
524
+ size: blob.properties?.contentLength ?? null
508
525
  }
509
526
  });
510
527
  }
@@ -537,4 +554,15 @@ async function listRemoteBlobNames(containerClient, includes) {
537
554
  remoteBlobs.add(blob.name);
538
555
  }
539
556
  return remoteBlobs;
557
+ }
558
+
559
+ function formatBytes(bytes) {
560
+ if (!bytes || bytes <= 0) {
561
+ return "0 B";
562
+ }
563
+
564
+ const units = ["B", "KB", "MB", "GB", "TB"];
565
+ const index = Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1);
566
+ const value = bytes / Math.pow(1024, index);
567
+ return `${value.toFixed(value >= 10 || index === 0 ? 0 : 1)} ${units[index]}`;
540
568
  }
@@ -56,18 +56,19 @@ export class AzureHelper {
56
56
  }
57
57
  }
58
58
 
59
- async uploadFile(containerClient, blobPath, filePath, md5Base64) {
59
+ async uploadFile(containerClient, blobPath, filePath, md5Base64, onProgress) {
60
60
  const blockBlobClient = containerClient.getBlockBlobClient(blobPath);
61
61
  const md5Buffer = md5Base64 ? Buffer.from(md5Base64, "base64") : undefined;
62
62
 
63
63
  await blockBlobClient.uploadFile(filePath, {
64
- blobHTTPHeaders: md5Buffer ? { blobContentMD5: md5Buffer } : undefined
64
+ blobHTTPHeaders: md5Buffer ? { blobContentMD5: md5Buffer } : undefined,
65
+ onProgress
65
66
  });
66
67
  }
67
68
 
68
- async downloadToFile(containerClient, blobPath, filePath) {
69
+ async downloadToFile(containerClient, blobPath, filePath, onProgress) {
69
70
  const blockBlobClient = containerClient.getBlockBlobClient(blobPath);
70
- await blockBlobClient.downloadToFile(filePath);
71
+ await blockBlobClient.downloadToFile(filePath, 0, 0, { onProgress });
71
72
  }
72
73
 
73
74
  async deleteBlob(containerClient, blobPath) {