@dignetwork/dig-sdk 0.0.1-alpha.81 → 0.0.1-alpha.84

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.
@@ -1 +1 @@
1
- {"version":3,"file":"PropagationServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/PropagationServer.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,MAAM,OAAO,CAAC;AAyB1B,qBAAa,iBAAiB;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAE7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAQ;gBAExB,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAY9C;;OAEG;IACG,gBAAgB;IAOtB;;OAEG;IACH,gBAAgB;IAQhB;;OAEG;IACG,gBAAgB,CACpB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,CAAC;IA0C7D;;OAEG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM;IAuDzC;;OAEG;IACG,YAAY,CAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,OAAO,CAAA;KAAE,CAAC;IAyBlD;;;OAGG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAoGhD;;OAEG;IACG,mBAAmB;IAgCzB;;OAEG;WACU,WAAW,C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AO,CAAC;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,CAAC;IA0C7D;;OAEG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM;IAuDzC;;OAEG;IACG,YAAY,CAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,OAAO,CAAA;KAAE,CAAC;IAyBlD;;;OAGG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAoGhD;;OAEG;IACG,mBAAmB;IAgCzB;;OAEG;WACU,WAAW,CACtB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;IA2DnB;;;OAGG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA0ElD;;OAEG;IACG,cAAc,CAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IA0B7C;;;OAGG;IACG,YAAY,CAChB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM;IA+FjB;;OAEG;WACU,aAAa,CACxB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;CAyFpB"}
@@ -483,7 +483,7 @@ class PropagationServer {
483
483
  // Prepare download tasks
484
484
  const downloadTasks = [];
485
485
  for (const [fileKey, fileData] of Object.entries(root.files)) {
486
- const dataPath = (0, hashUtils_1.getFilePathFromSha256)(fileData.sha256, "data");
486
+ const dataPath = (0, hashUtils_1.getFilePathFromSha256)(root.files[fileKey].sha256, "data");
487
487
  const label = Buffer.from(fileKey, "hex").toString("utf-8");
488
488
  downloadTasks.push({ label, dataPath });
489
489
  }
@@ -494,32 +494,36 @@ class PropagationServer {
494
494
  try {
495
495
  // Download files to the temporary directory
496
496
  await (0, asyncPool_1.asyncPool)(concurrencyLimit, downloadTasks, async (task) => {
497
- await propagationServer.downloadFile(task.label, task.dataPath, rootHash, path_1.default.join(tempDir, storeId));
497
+ await propagationServer.downloadFile(task.label, task.dataPath, rootHash, tempDir);
498
498
  });
499
499
  // Save the rootHash.dat file to the temporary directory
500
- fs_1.default.writeFileSync(path_1.default.join(tempDir, storeId, `${rootHash}.dat`), datFileContent);
500
+ if (!fs_1.default.existsSync(tempDir)) {
501
+ fs_1.default.mkdirSync(tempDir, { recursive: true });
502
+ }
503
+ fs_1.default.writeFileSync(path_1.default.join(tempDir, `${rootHash}.dat`), datFileContent);
501
504
  // Integrity check for the downloaded files was done during the download
502
505
  // Here we want to make sure we got all the files or we reject the download session
503
- /*for (const [fileKey, fileData] of Object.entries(root.files)) {
504
- const dataPath = getFilePathFromSha256(
505
- (fileData as any).sha256,
506
- "data"
507
- );
508
-
509
- const downloadPath = path.join(tempDir, storeId, dataPath);
510
- if (!fs.existsSync(path.join(downloadPath, dataPath))) {
511
- throw new Error(`Missing file!: ${Buffer.from(fileKey, "utf-8")}, aborting session.`);
512
- }
513
- }*/
506
+ for (const [fileKey, fileData] of Object.entries(root.files)) {
507
+ const dataPath = (0, hashUtils_1.getFilePathFromSha256)(root.files[fileKey].sha256, "data");
508
+ if (!fs_1.default.existsSync(path_1.default.join(tempDir, dataPath))) {
509
+ throw new Error(`Missing file: ${Buffer.from(fileKey, "hex")}, aborting session.`);
510
+ }
511
+ }
514
512
  // After all downloads are complete, copy from temp directory to the main directory
515
513
  const destinationDir = path_1.default.join(config_1.STORE_PATH, storeId);
516
- fs_extra_1.default.copySync(path_1.default.join(tempDir, storeId), destinationDir);
514
+ fs_extra_1.default.copySync(tempDir, destinationDir, {
515
+ overwrite: false, // Prevents overwriting existing files
516
+ errorOnExist: false, // No error if file already exists
517
+ });
517
518
  // Generate the manifest file in the main directory
518
519
  const dataStore = blockchain_1.DataStore.from(storeId);
519
520
  await dataStore.cacheStoreCreationHeight();
520
521
  await dataStore.generateManifestFile();
521
522
  console.log((0, colorette_1.green)(`✔ All files have been downloaded to ${storeId}.`));
522
523
  }
524
+ catch (error) {
525
+ console.log((0, colorette_1.red)("✖ Error downloading files:"), error);
526
+ }
523
527
  finally {
524
528
  // Clean up the temporary directory
525
529
  fs_extra_1.default.removeSync(tempDir);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/dig-sdk",
3
- "version": "0.0.1-alpha.81",
3
+ "version": "0.0.1-alpha.84",
4
4
  "description": "",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",