bulltrackers-module 1.0.415 → 1.0.416
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.
|
@@ -13,10 +13,39 @@ const zlib = require('zlib');
|
|
|
13
13
|
function tryDecompress(data) {
|
|
14
14
|
if (data && data._compressed === true && data.payload) {
|
|
15
15
|
try {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
let buffer;
|
|
17
|
+
|
|
18
|
+
// Handle different payload types from Firestore
|
|
19
|
+
if (Buffer.isBuffer(data.payload)) {
|
|
20
|
+
// Already a Buffer
|
|
21
|
+
buffer = data.payload;
|
|
22
|
+
} else if (typeof data.payload === 'string') {
|
|
23
|
+
// If it's a string, it might be base64 encoded or already decompressed
|
|
24
|
+
// Try to convert to Buffer first
|
|
25
|
+
try {
|
|
26
|
+
buffer = Buffer.from(data.payload, 'base64');
|
|
27
|
+
} catch (e) {
|
|
28
|
+
// If not base64, try direct string (might already be JSON string)
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(data.payload);
|
|
31
|
+
} catch (e2) {
|
|
32
|
+
buffer = Buffer.from(data.payload);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
} else if (data.payload.constructor && data.payload.constructor.name === 'Blob') {
|
|
36
|
+
// Firestore Blob type - convert to Buffer
|
|
37
|
+
buffer = Buffer.from(data.payload.toUint8Array());
|
|
38
|
+
} else {
|
|
39
|
+
// Try to convert to Buffer
|
|
40
|
+
buffer = Buffer.from(data.payload);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Decompress and parse
|
|
44
|
+
const decompressed = zlib.gunzipSync(buffer);
|
|
45
|
+
const jsonString = decompressed.toString('utf8');
|
|
46
|
+
return JSON.parse(jsonString);
|
|
18
47
|
} catch (e) {
|
|
19
|
-
console.error('[DataHelpers] Decompression failed:', e);
|
|
48
|
+
console.error('[DataHelpers] Decompression failed:', e.message, e.stack);
|
|
20
49
|
// Return empty object on failure to avoid crashing
|
|
21
50
|
return {};
|
|
22
51
|
}
|
|
@@ -1444,22 +1473,49 @@ async function getPiProfile(req, res, dependencies, config) {
|
|
|
1444
1473
|
logger.log('INFO', `[getPiProfile] Document exists. Was compressed: ${wasCompressed}, CID being searched: ${cid}`);
|
|
1445
1474
|
logger.log('INFO', `[getPiProfile] Raw data keys:`, rawData ? Object.keys(rawData).slice(0, 10) : 'NO DATA');
|
|
1446
1475
|
|
|
1447
|
-
|
|
1476
|
+
if (wasCompressed && rawData.payload) {
|
|
1477
|
+
logger.log('INFO', `[getPiProfile] Payload type: ${typeof rawData.payload}, isBuffer: ${Buffer.isBuffer(rawData.payload)}`);
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
let computationData = tryDecompress(rawData);
|
|
1481
|
+
|
|
1482
|
+
// Check if decompression returned a string (which would indicate a problem)
|
|
1483
|
+
if (typeof computationData === 'string') {
|
|
1484
|
+
logger.log('WARN', `[getPiProfile] Decompression returned a STRING instead of an object. Length: ${computationData.length}`);
|
|
1485
|
+
logger.log('WARN', `[getPiProfile] First 500 chars of decompressed string:`, computationData.substring(0, 500));
|
|
1486
|
+
// Try to parse it as JSON
|
|
1487
|
+
try {
|
|
1488
|
+
computationData = JSON.parse(computationData);
|
|
1489
|
+
logger.log('INFO', `[getPiProfile] Successfully parsed string as JSON`);
|
|
1490
|
+
} catch (e) {
|
|
1491
|
+
logger.log('ERROR', `[getPiProfile] Failed to parse decompressed string as JSON:`, e.message);
|
|
1492
|
+
return res.status(500).json({
|
|
1493
|
+
error: "Data parsing failed",
|
|
1494
|
+
message: "Failed to parse decompressed computation data"
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1448
1498
|
|
|
1449
1499
|
// Debug logging: Show full decompressed document structure
|
|
1450
1500
|
logger.log('INFO', `[getPiProfile] Decompressed data structure:`, {
|
|
1451
1501
|
hasData: !!computationData,
|
|
1452
1502
|
dataType: typeof computationData,
|
|
1453
1503
|
isArray: Array.isArray(computationData),
|
|
1454
|
-
|
|
1455
|
-
|
|
1504
|
+
isString: typeof computationData === 'string',
|
|
1505
|
+
keys: computationData && typeof computationData === 'object' && !Array.isArray(computationData) ? Object.keys(computationData).slice(0, 50) : 'N/A', // First 50 keys
|
|
1506
|
+
totalKeys: computationData && typeof computationData === 'object' && !Array.isArray(computationData) ? Object.keys(computationData).length : 0,
|
|
1456
1507
|
searchingForCid: String(cid),
|
|
1457
|
-
cidExists: computationData && computationData[String(cid)] !== undefined,
|
|
1458
|
-
sampleCids: computationData && typeof computationData === 'object' ? Object.keys(computationData).slice(0, 10) : []
|
|
1508
|
+
cidExists: computationData && typeof computationData === 'object' && !Array.isArray(computationData) ? computationData[String(cid)] !== undefined : false,
|
|
1509
|
+
sampleCids: computationData && typeof computationData === 'object' && !Array.isArray(computationData) ? Object.keys(computationData).slice(0, 10) : []
|
|
1459
1510
|
});
|
|
1460
1511
|
|
|
1461
1512
|
// Log full decompressed data (will be large but needed for debugging)
|
|
1462
|
-
|
|
1513
|
+
// Only stringify if it's an object, not a string
|
|
1514
|
+
if (typeof computationData === 'object' && !Array.isArray(computationData)) {
|
|
1515
|
+
logger.log('INFO', `[getPiProfile] FULL DECOMPRESSED DOCUMENT CONTENTS (first 2000 chars):`, JSON.stringify(computationData, null, 2).substring(0, 2000));
|
|
1516
|
+
} else {
|
|
1517
|
+
logger.log('INFO', `[getPiProfile] FULL DECOMPRESSED DOCUMENT CONTENTS (first 2000 chars):`, String(computationData).substring(0, 2000));
|
|
1518
|
+
}
|
|
1463
1519
|
|
|
1464
1520
|
const cidStr = String(cid);
|
|
1465
1521
|
const profileData = computationData && typeof computationData === 'object' ? computationData[cidStr] : undefined;
|