Skip to content

Commit c5840ff

Browse files
Merge pull request #66 from DIG-Network/release/v0.0.1-alpha.71
Release/v0.0.1 alpha.71
2 parents 86f8ea8 + 8900adb commit c5840ff

File tree

4 files changed

+32
-29
lines changed

4 files changed

+32
-29
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
### [0.0.1-alpha.71](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.70...v0.0.1-alpha.71) (2024-09-23)
6+
7+
8+
### Bug Fixes
9+
10+
* bad propagation server constructor ([305782f](https://github.com/DIG-Network/dig-chia-sdk/commit/305782f03e6c5d99da01efd962a29bf04078155e))
11+
512
### [0.0.1-alpha.70](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.69...v0.0.1-alpha.70) (2024-09-23)
613

714

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dignetwork/dig-sdk",
3-
"version": "0.0.1-alpha.70",
3+
"version": "0.0.1-alpha.71",
44
"description": "",
55
"type": "commonjs",
66
"main": "./dist/index.js",

src/DigNetwork/PropagationServer.ts

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -417,37 +417,32 @@ export class PropagationServer {
417417
const config: AxiosRequestConfig = {
418418
responseType: "arraybuffer", // To store the file content in memory
419419
httpsAgent: this.createHttpsAgent(),
420-
};
421-
422-
const url = `https://${this.ipAddress}:${PropagationServer.port}/fetch/${this.storeId}/${dataPath}`;
423-
424-
try {
425-
const response = await axios.get(url, config);
426-
const totalLength = parseInt(response.headers["content-length"], 10);
427-
428-
console.log(cyan(`Starting fetch for ${dataPath}...`));
429-
430-
// Create a progress bar for the download
431-
const progressBar = PropagationServer.multiBar.create(totalLength, 0, {
432-
dataPath: yellow(dataPath),
433-
percentage: 0,
434-
});
435-
436-
let downloadedBytes = 0;
420+
onDownloadProgress: (progressEvent) => {
421+
const totalLength = progressEvent.total || 0;
422+
const downloadedBytes = progressEvent.loaded;
423+
424+
// Update progress bar
425+
const progressBar = PropagationServer.multiBar.create(totalLength, 0, {
426+
dataPath: yellow(dataPath),
427+
percentage: 0,
428+
});
437429

438-
// Track progress of downloading the file
439-
response.data.on("data", (chunk: Buffer) => {
440-
downloadedBytes += chunk.length;
441430
progressBar.update(downloadedBytes, {
442431
percentage: Math.round((downloadedBytes / totalLength) * 100),
443432
});
444-
});
445433

446-
// Complete the progress bar once done
447-
progressBar.update(totalLength, { percentage: 100 });
448-
progressBar.stop();
434+
if (downloadedBytes === totalLength) {
435+
progressBar.update(totalLength, { percentage: 100 });
436+
progressBar.stop();
437+
console.log(green(`✔ File ${dataPath} fetched successfully.`));
438+
}
439+
},
440+
};
449441

450-
console.log(green(`✔ File ${dataPath} fetched successfully.`));
442+
const url = `https://${this.ipAddress}:${PropagationServer.port}/fetch/${this.storeId}/${dataPath}`;
443+
444+
try {
445+
const response = await axios.get(url, config);
451446

452447
// Return the file contents as a Buffer
453448
return Buffer.from(response.data);
@@ -581,7 +576,8 @@ export class PropagationServer {
581576
await propagationServer.initializeWallet();
582577

583578
// Check if the store exists
584-
const { storeExists, rootHashExists} = await propagationServer.checkStoreExists(rootHash);
579+
const { storeExists, rootHashExists } =
580+
await propagationServer.checkStoreExists(rootHash);
585581
if (!storeExists || !rootHashExists) {
586582
throw new Error(`Store ${storeId} does not exist.`);
587583
}

0 commit comments

Comments
 (0)