@dignetwork/dig-sdk 0.0.1-alpha.14 → 0.0.1-alpha.142
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/dist/DataIntegrityTree/DataIntegrityTree.d.ts +11 -2
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +1 -1
- package/dist/DataIntegrityTree/DataIntegrityTree.js +106 -15
- package/dist/DigNetwork/ContentServer.d.ts +12 -5
- package/dist/DigNetwork/ContentServer.d.ts.map +1 -1
- package/dist/DigNetwork/ContentServer.js +172 -24
- package/dist/DigNetwork/DigNetwork.d.ts +6 -9
- package/dist/DigNetwork/DigNetwork.d.ts.map +1 -1
- package/dist/DigNetwork/DigNetwork.js +137 -189
- package/dist/DigNetwork/DigPeer.d.ts +8 -3
- package/dist/DigNetwork/DigPeer.d.ts.map +1 -1
- package/dist/DigNetwork/DigPeer.js +68 -115
- package/dist/DigNetwork/IncentiveServer.d.ts.map +1 -1
- package/dist/DigNetwork/IncentiveServer.js +6 -5
- package/dist/DigNetwork/PropagationServer.d.ts +83 -33
- package/dist/DigNetwork/PropagationServer.d.ts.map +1 -1
- package/dist/DigNetwork/PropagationServer.js +605 -356
- package/dist/blockchain/DataStore.d.ts +25 -7
- package/dist/blockchain/DataStore.d.ts.map +1 -1
- package/dist/blockchain/DataStore.js +114 -159
- package/dist/blockchain/DataStoreSerializer.d.ts +1 -1
- package/dist/blockchain/DataStoreSerializer.d.ts.map +1 -1
- package/dist/blockchain/FullNodePeer.d.ts +92 -9
- package/dist/blockchain/FullNodePeer.d.ts.map +1 -1
- package/dist/blockchain/FullNodePeer.js +329 -130
- package/dist/blockchain/ServerCoin.d.ts +13 -5
- package/dist/blockchain/ServerCoin.d.ts.map +1 -1
- package/dist/blockchain/ServerCoin.js +90 -28
- package/dist/blockchain/StoreMonitorRegistry.d.ts +85 -0
- package/dist/blockchain/StoreMonitorRegistry.d.ts.map +1 -0
- package/dist/blockchain/StoreMonitorRegistry.js +242 -0
- package/dist/blockchain/Wallet.d.ts +2 -2
- package/dist/blockchain/Wallet.d.ts.map +1 -1
- package/dist/blockchain/Wallet.js +50 -18
- package/dist/blockchain/coins.d.ts +1 -2
- package/dist/blockchain/coins.d.ts.map +1 -1
- package/dist/blockchain/coins.js +1 -55
- package/dist/blockchain/index.d.ts +1 -0
- package/dist/blockchain/index.d.ts.map +1 -1
- package/dist/blockchain/index.js +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/ContentScanner.d.ts +63 -0
- package/dist/utils/ContentScanner.d.ts.map +1 -0
- package/dist/utils/ContentScanner.js +175 -0
- package/dist/utils/Environment.d.ts +21 -0
- package/dist/utils/Environment.d.ts.map +1 -0
- package/dist/utils/Environment.js +92 -0
- package/dist/utils/FileCache.d.ts +1 -1
- package/dist/utils/FileCache.d.ts.map +1 -1
- package/dist/utils/FileCache.js +2 -2
- package/dist/utils/FileTransfer.d.ts +47 -0
- package/dist/utils/FileTransfer.d.ts.map +1 -0
- package/dist/utils/FileTransfer.js +209 -0
- package/dist/utils/NconfManager.js +2 -1
- package/dist/utils/StoreArchiveManager.d.ts +45 -0
- package/dist/utils/StoreArchiveManager.d.ts.map +1 -0
- package/dist/utils/StoreArchiveManager.js +153 -0
- package/dist/utils/config.d.ts +4 -3
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +12 -7
- package/dist/utils/directoryUtils.d.ts.map +1 -1
- package/dist/utils/directoryUtils.js +9 -8
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/merkle.d.ts +2 -0
- package/dist/utils/merkle.d.ts.map +1 -0
- package/dist/utils/merkle.js +28 -0
- package/dist/utils/network.d.ts +1 -0
- package/dist/utils/network.d.ts.map +1 -1
- package/dist/utils/network.js +38 -11
- package/dist/utils/promiseUtils.d.ts +17 -0
- package/dist/utils/promiseUtils.d.ts.map +1 -0
- package/dist/utils/promiseUtils.js +38 -0
- package/dist/utils/ssl.js +2 -2
- package/package.json +17 -5
- package/dist/utils/deltaUtils.d.ts +0 -2
- package/dist/utils/deltaUtils.d.ts.map +0 -1
- package/dist/utils/deltaUtils.js +0 -83
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.merkleIntegrityCheck = merkleIntegrityCheck;
|
|
7
|
+
const DataIntegrityTree_1 = require("../DataIntegrityTree");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
async function merkleIntegrityCheck(treePath, tmpDir, dataPath, roothash) {
|
|
11
|
+
const rootHashContent = fs_1.default.readFileSync(treePath, "utf-8");
|
|
12
|
+
const tree = JSON.parse(rootHashContent);
|
|
13
|
+
// Extract expected sha256 from dataPath
|
|
14
|
+
const expectedSha256 = dataPath.replace("data", "").replace(/\//g, "");
|
|
15
|
+
console.log("expectedSha256", expectedSha256);
|
|
16
|
+
// Find the hexKey in the tree based on matching sha256
|
|
17
|
+
const hexKey = Object.keys(tree.files).find((key) => {
|
|
18
|
+
const fileData = tree.files[key]; // Inline type definition
|
|
19
|
+
return fileData.sha256 === expectedSha256;
|
|
20
|
+
});
|
|
21
|
+
if (!hexKey) {
|
|
22
|
+
throw new Error(`No matching file found with sha256: ${expectedSha256}`);
|
|
23
|
+
}
|
|
24
|
+
// Validate the integrity with the foreign tree
|
|
25
|
+
const integrity = await DataIntegrityTree_1.DataIntegrityTree.validateKeyIntegrityWithForeignTree(hexKey, expectedSha256, tree, roothash, path_1.default.join(tmpDir, "data"));
|
|
26
|
+
console.log("Integrity check result:", integrity);
|
|
27
|
+
return integrity;
|
|
28
|
+
}
|
package/dist/utils/network.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,kBAAkB,QAAa,OAAO,CAAC,MAAM,GAAG,SAAS,CA6CrE,CAAC;AAGF,eAAO,MAAM,UAAU,SAAU,MAAM,KAAG,MAUzC,CAAC"}
|
package/dist/utils/network.js
CHANGED
|
@@ -3,36 +3,63 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPublicIpAddress = void 0;
|
|
6
|
+
exports.formatHost = exports.getPublicIpAddress = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Stopgap until better solution for finding public IPS found
|
|
9
|
+
*/
|
|
7
10
|
const superagent_1 = __importDefault(require("superagent"));
|
|
11
|
+
const Environment_1 = require("./Environment");
|
|
8
12
|
const MAX_RETRIES = 5;
|
|
9
13
|
const RETRY_DELAY = 2000; // in milliseconds
|
|
14
|
+
// Regular expression for validating both IPv4 and IPv6 addresses
|
|
15
|
+
const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
16
|
+
const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7}([0-9a-fA-F]{1,4}|:)|(([0-9a-fA-F]{1,4}:){1,7}|:):(([0-9a-fA-F]{1,4}:){1,6}|:):([0-9a-fA-F]{1,4}|:):([0-9a-fA-F]{1,4}|:)|::)$/;
|
|
17
|
+
// Helper function to validate the IP address
|
|
18
|
+
const isValidIp = (ip) => {
|
|
19
|
+
return ipv4Regex.test(ip) || ipv6Regex.test(ip);
|
|
20
|
+
};
|
|
10
21
|
const getPublicIpAddress = async () => {
|
|
11
|
-
const publicIp =
|
|
22
|
+
const publicIp = Environment_1.Environment.PUBLIC_IP;
|
|
12
23
|
if (publicIp) {
|
|
13
|
-
console.log(
|
|
14
|
-
|
|
24
|
+
console.log("Public IP address from env:", publicIp);
|
|
25
|
+
if (isValidIp(publicIp)) {
|
|
26
|
+
return publicIp;
|
|
27
|
+
}
|
|
28
|
+
console.error("Invalid public IP address in environment variable");
|
|
29
|
+
return undefined;
|
|
15
30
|
}
|
|
16
31
|
let attempt = 0;
|
|
17
32
|
while (attempt < MAX_RETRIES) {
|
|
18
33
|
try {
|
|
19
|
-
const response = await superagent_1.default.get(
|
|
34
|
+
const response = await superagent_1.default.get("https://api.datalayer.storage/user/v1/get_user_ip");
|
|
20
35
|
if (response.body && response.body.success) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
throw new Error(
|
|
36
|
+
const ipAddress = response.body.ip_address;
|
|
37
|
+
if (isValidIp(ipAddress)) {
|
|
38
|
+
return ipAddress;
|
|
39
|
+
}
|
|
40
|
+
throw new Error("Invalid IP address format received");
|
|
26
41
|
}
|
|
42
|
+
throw new Error("Failed to retrieve public IP address");
|
|
27
43
|
}
|
|
28
44
|
catch (error) {
|
|
29
45
|
attempt++;
|
|
30
46
|
console.error(`Error fetching public IP address (Attempt ${attempt}):`, error.message);
|
|
31
47
|
if (attempt >= MAX_RETRIES) {
|
|
32
|
-
throw new Error(
|
|
48
|
+
throw new Error("Could not retrieve public IP address after several attempts");
|
|
33
49
|
}
|
|
34
50
|
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
|
|
35
51
|
}
|
|
36
52
|
}
|
|
37
53
|
};
|
|
38
54
|
exports.getPublicIpAddress = getPublicIpAddress;
|
|
55
|
+
// Helper function to wrap IPv6 addresses in brackets
|
|
56
|
+
const formatHost = (host) => {
|
|
57
|
+
const ipv6Pattern = /^[a-fA-F0-9:]+$/; // Simple regex to match raw IPv6 addresses (without brackets)
|
|
58
|
+
const hasBrackets = /^\[.*\]$/; // Regex to check if the address already has brackets
|
|
59
|
+
// If it's an IPv6 address without brackets, add them
|
|
60
|
+
if (ipv6Pattern.test(host) && !hasBrackets.test(host)) {
|
|
61
|
+
return `[${host}]`;
|
|
62
|
+
}
|
|
63
|
+
return host; // Return the host as is (IPv4, hostname, or already bracketed IPv6)
|
|
64
|
+
};
|
|
65
|
+
exports.formatHost = formatHost;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Processes items in sequential batches with a concurrency limit.
|
|
3
|
+
* @param {number} limit - The maximum number of concurrent executions per batch.
|
|
4
|
+
* @param {Array<T>} items - The array of items to process.
|
|
5
|
+
* @param {(item: T) => Promise<R>} iteratorFn - The async function to apply to each item.
|
|
6
|
+
* @returns {Promise<Array<R>>} - A promise that resolves when all items have been processed.
|
|
7
|
+
*/
|
|
8
|
+
export declare function asyncPool<T, R>(limit: number, items: T[], iteratorFn: (item: T) => Promise<R>): Promise<R[]>;
|
|
9
|
+
/**
|
|
10
|
+
* Helper function to add a timeout to a promise.
|
|
11
|
+
* @param promise The original promise.
|
|
12
|
+
* @param ms Timeout in milliseconds.
|
|
13
|
+
* @param timeoutMessage The error message when the timeout is reached.
|
|
14
|
+
* @returns Promise that resolves before the timeout or rejects with an error.
|
|
15
|
+
*/
|
|
16
|
+
export declare const withTimeout: <T>(promise: Promise<T>, ms: number, timeoutMessage: string) => Promise<T>;
|
|
17
|
+
//# sourceMappingURL=promiseUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promiseUtils.d.ts","sourceRoot":"","sources":["../../src/utils/promiseUtils.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAAE,CAAC,EAChC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,CAAC,EAAE,EACV,UAAU,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAClC,OAAO,CAAC,CAAC,EAAE,CAAC,CAgBd;AAED;;;;;;EAMC;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,WAClB,OAAO,CAAC,CAAC,CAAC,MACf,MAAM,kBACM,MAAM,KACrB,OAAO,CAAC,CAAC,CAOX,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withTimeout = void 0;
|
|
4
|
+
exports.asyncPool = asyncPool;
|
|
5
|
+
/**
|
|
6
|
+
* Processes items in sequential batches with a concurrency limit.
|
|
7
|
+
* @param {number} limit - The maximum number of concurrent executions per batch.
|
|
8
|
+
* @param {Array<T>} items - The array of items to process.
|
|
9
|
+
* @param {(item: T) => Promise<R>} iteratorFn - The async function to apply to each item.
|
|
10
|
+
* @returns {Promise<Array<R>>} - A promise that resolves when all items have been processed.
|
|
11
|
+
*/
|
|
12
|
+
async function asyncPool(limit, items, iteratorFn) {
|
|
13
|
+
const ret = [];
|
|
14
|
+
for (let i = 0; i < items.length; i += limit) {
|
|
15
|
+
const batchItems = items.slice(i, i + limit);
|
|
16
|
+
const batchPromises = batchItems.map((item) => iteratorFn(item));
|
|
17
|
+
// Wait for the current batch to complete before starting the next one
|
|
18
|
+
const batchResults = await Promise.all(batchPromises);
|
|
19
|
+
ret.push(...batchResults);
|
|
20
|
+
// Optional: add a cooldown between batches
|
|
21
|
+
// await new Promise((resolve) => setTimeout(resolve, 500));
|
|
22
|
+
}
|
|
23
|
+
return ret;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Helper function to add a timeout to a promise.
|
|
27
|
+
* @param promise The original promise.
|
|
28
|
+
* @param ms Timeout in milliseconds.
|
|
29
|
+
* @param timeoutMessage The error message when the timeout is reached.
|
|
30
|
+
* @returns Promise that resolves before the timeout or rejects with an error.
|
|
31
|
+
*/
|
|
32
|
+
const withTimeout = (promise, ms, timeoutMessage) => {
|
|
33
|
+
return Promise.race([
|
|
34
|
+
promise,
|
|
35
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error(timeoutMessage)), ms)),
|
|
36
|
+
]);
|
|
37
|
+
};
|
|
38
|
+
exports.withTimeout = withTimeout;
|
package/dist/utils/ssl.js
CHANGED
|
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.getOrCreateSSLCerts = void 0;
|
|
27
27
|
const fs = __importStar(require("fs"));
|
|
28
28
|
const path = __importStar(require("path"));
|
|
29
|
-
const
|
|
29
|
+
const datalayer_driver_1 = require("@dignetwork/datalayer-driver");
|
|
30
30
|
const config_1 = require("./config");
|
|
31
31
|
const getOrCreateSSLCerts = () => {
|
|
32
32
|
const sslDir = path.join(config_1.USER_DIR_PATH, "ssl");
|
|
@@ -38,7 +38,7 @@ const getOrCreateSSLCerts = () => {
|
|
|
38
38
|
}
|
|
39
39
|
// Check if the certificate and key exist, if not, generate them
|
|
40
40
|
if (!fs.existsSync(certPath) || !fs.existsSync(keyPath)) {
|
|
41
|
-
new
|
|
41
|
+
new datalayer_driver_1.Tls(certPath, keyPath);
|
|
42
42
|
console.log("Client certificate and key generated successfully.");
|
|
43
43
|
}
|
|
44
44
|
// Return the paths to the cert and key files
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dignetwork/dig-sdk",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.142",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,15 +25,20 @@
|
|
|
25
25
|
"LICENSE"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"@dignetwork/datalayer-driver": "^0.1.29",
|
|
29
|
+
"@dignetwork/dig-sdk": "^0.0.1-alpha.124",
|
|
30
|
+
"archiver": "^7.0.1",
|
|
31
|
+
"axios": "^1.7.7",
|
|
28
32
|
"bip39": "^3.1.0",
|
|
33
|
+
"bottleneck": "^2.19.5",
|
|
29
34
|
"chia-bls": "^1.0.2",
|
|
30
35
|
"chia-config-loader": "^1.0.1",
|
|
31
36
|
"chia-root-resolver": "^1.0.0",
|
|
32
|
-
"chia-server-coin": "^0.0.5",
|
|
33
37
|
"chia-wallet": "^1.0.18",
|
|
34
38
|
"cli-progress": "^3.12.0",
|
|
39
|
+
"colorette": "^2.0.20",
|
|
35
40
|
"crypto-js": "^4.2.0",
|
|
36
|
-
"
|
|
41
|
+
"figures": "^6.1.0",
|
|
37
42
|
"fs-extra": "^11.2.0",
|
|
38
43
|
"ignore": "^5.3.2",
|
|
39
44
|
"inquirer": "^10.1.8",
|
|
@@ -41,10 +46,14 @@
|
|
|
41
46
|
"merkletreejs": "^0.4.0",
|
|
42
47
|
"nanospinner": "^1.1.0",
|
|
43
48
|
"nconf": "^0.12.1",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
49
|
+
"node-cache": "^5.1.2",
|
|
50
|
+
"progress-stream": "^2.0.0",
|
|
51
|
+
"proper-lockfile": "^4.1.2",
|
|
52
|
+
"superagent": "^10.0.0",
|
|
53
|
+
"unzipper": "^0.12.3"
|
|
46
54
|
},
|
|
47
55
|
"devDependencies": {
|
|
56
|
+
"@types/archiver": "^6.0.2",
|
|
48
57
|
"@types/chai": "^4.3.17",
|
|
49
58
|
"@types/cli-progress": "^3.11.6",
|
|
50
59
|
"@types/crypto-js": "^4.2.2",
|
|
@@ -54,7 +63,10 @@
|
|
|
54
63
|
"@types/mocha": "^10.0.7",
|
|
55
64
|
"@types/nconf": "^0.10.7",
|
|
56
65
|
"@types/node": "^22.1.0",
|
|
66
|
+
"@types/progress-stream": "^2.0.5",
|
|
67
|
+
"@types/proper-lockfile": "^4.1.4",
|
|
57
68
|
"@types/superagent": "^8.1.8",
|
|
69
|
+
"@types/unzipper": "^0.10.10",
|
|
58
70
|
"chai": "^5.1.1",
|
|
59
71
|
"copyfiles": "^2.4.1",
|
|
60
72
|
"mocha": "^10.7.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deltaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deltaUtils.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,YACf,MAAM,mBACE,MAAM,6BACR,MAAM,KACpB,OAAO,CAAC,MAAM,EAAE,CAwElB,CAAC"}
|
package/dist/utils/deltaUtils.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getDeltaFiles = void 0;
|
|
27
|
-
const fs = __importStar(require("fs"));
|
|
28
|
-
const path = __importStar(require("path"));
|
|
29
|
-
const hashUtils_1 = require("./hashUtils");
|
|
30
|
-
const getDeltaFiles = async (storeId, generationIndex = 0, directoryPath) => {
|
|
31
|
-
if (isNaN(generationIndex)) {
|
|
32
|
-
generationIndex = 0;
|
|
33
|
-
}
|
|
34
|
-
// Load manifest file
|
|
35
|
-
const manifestFilePath = path.join(directoryPath, storeId, "manifest.dat");
|
|
36
|
-
if (!fs.existsSync(manifestFilePath)) {
|
|
37
|
-
console.error("Manifest file not found", manifestFilePath);
|
|
38
|
-
return [];
|
|
39
|
-
}
|
|
40
|
-
const manifestHashes = fs
|
|
41
|
-
.readFileSync(manifestFilePath, "utf-8")
|
|
42
|
-
.split("\n")
|
|
43
|
-
.filter(Boolean);
|
|
44
|
-
console.log("");
|
|
45
|
-
console.log(`Uploading delta from generation ${generationIndex}`);
|
|
46
|
-
const filesInvolved = [];
|
|
47
|
-
// Include the height.dat file at the top of the directory
|
|
48
|
-
const heightDatFilePath = path.join(directoryPath, storeId, "height.json");
|
|
49
|
-
if (fs.existsSync(heightDatFilePath)) {
|
|
50
|
-
filesInvolved.push(heightDatFilePath);
|
|
51
|
-
}
|
|
52
|
-
// Collect files starting from generationIndex + 1
|
|
53
|
-
for (let i = generationIndex; i < manifestHashes.length; i++) {
|
|
54
|
-
const rootHash = manifestHashes[i];
|
|
55
|
-
const datFilePath = path.join(directoryPath, storeId, `${rootHash}.dat`);
|
|
56
|
-
if (!fs.existsSync(datFilePath)) {
|
|
57
|
-
console.error(`Data file for root hash ${rootHash} not found`);
|
|
58
|
-
return [];
|
|
59
|
-
}
|
|
60
|
-
const datFileContent = JSON.parse(fs.readFileSync(datFilePath, "utf-8"));
|
|
61
|
-
if (datFileContent.root !== rootHash) {
|
|
62
|
-
console.error(`Root hash in data file does not match: ${datFileContent.root} !== ${rootHash}`);
|
|
63
|
-
return [];
|
|
64
|
-
}
|
|
65
|
-
// Add the .dat file itself to the list of files involved
|
|
66
|
-
filesInvolved.push(datFilePath);
|
|
67
|
-
// Collect all files involved, ensuring correct paths
|
|
68
|
-
for (const file of Object.keys(datFileContent.files)) {
|
|
69
|
-
const filePath = (0, hashUtils_1.getFilePathFromSha256)(datFileContent.files[file].sha256, path.join(directoryPath, storeId, "data"));
|
|
70
|
-
filesInvolved.push(filePath);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (process.env.DIG_DEBUG === "1") {
|
|
74
|
-
console.log("Files involved in the delta:");
|
|
75
|
-
console.table(filesInvolved);
|
|
76
|
-
}
|
|
77
|
-
// list the manifest file last, this actually
|
|
78
|
-
// helps with upload because by overriding the manifest file last,
|
|
79
|
-
// the store can still be considered valid even when the upload is interrupted
|
|
80
|
-
filesInvolved.push(manifestFilePath);
|
|
81
|
-
return filesInvolved;
|
|
82
|
-
};
|
|
83
|
-
exports.getDeltaFiles = getDeltaFiles;
|