@aj-archipelago/cortex 1.4.4 → 1.4.5
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/lib/crypto.js +28 -1
- package/lib/util.js +5 -1
- package/package.json +1 -1
package/lib/crypto.js
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
import logger from './logger.js';
|
|
3
3
|
import crypto from 'crypto';
|
|
4
4
|
|
|
5
|
+
// Helper function to generate a preview of a message for logging
|
|
6
|
+
function getMessagePreview(message, maxLength = 50) {
|
|
7
|
+
if (typeof message === 'string') {
|
|
8
|
+
return message.substring(0, maxLength);
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
return JSON.stringify(message).substring(0, maxLength);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
return String(message).substring(0, maxLength);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
5
17
|
// Encryption function
|
|
6
18
|
function encrypt(text, key) {
|
|
7
19
|
if (!key) { return text; }
|
|
@@ -22,6 +34,20 @@ function encrypt(text, key) {
|
|
|
22
34
|
function decrypt(message, key) {
|
|
23
35
|
if (!key) { return message; }
|
|
24
36
|
try {
|
|
37
|
+
// Quick type check - if not string, convert or skip
|
|
38
|
+
if (typeof message !== 'string') {
|
|
39
|
+
if (Buffer.isBuffer(message)) {
|
|
40
|
+
message = message.toString('utf8');
|
|
41
|
+
} else if (message === null || message === undefined) {
|
|
42
|
+
logger.warn(`Decryption skipped: message is ${message === null ? 'null' : 'undefined'}`);
|
|
43
|
+
return null;
|
|
44
|
+
} else {
|
|
45
|
+
const preview = getMessagePreview(message);
|
|
46
|
+
logger.warn(`Decryption skipped: message is not a string (type: ${typeof message}, preview: ${preview})`);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
25
51
|
key = tryBufferKey(key);
|
|
26
52
|
let parts = message.split(':');
|
|
27
53
|
let iv = Buffer.from(parts.shift(), 'hex');
|
|
@@ -31,7 +57,8 @@ function decrypt(message, key) {
|
|
|
31
57
|
decrypted += decipher.final('utf8');
|
|
32
58
|
return decrypted;
|
|
33
59
|
} catch (error) {
|
|
34
|
-
|
|
60
|
+
const preview = getMessagePreview(message);
|
|
61
|
+
logger.error(`Decryption failed: ${error.message} (preview: ${preview})`);
|
|
35
62
|
return null;
|
|
36
63
|
}
|
|
37
64
|
}
|
package/lib/util.js
CHANGED
|
@@ -475,8 +475,12 @@ const uploadImageToCloud = async (base64Data, mimeType, pathwayResolver = null)
|
|
|
475
475
|
contentType: mimeType
|
|
476
476
|
});
|
|
477
477
|
|
|
478
|
+
// Append requestId parameter (preserving existing query parameters like subscription-key)
|
|
479
|
+
const separator = fileHandlerUrl.includes('?') ? '&' : '?';
|
|
480
|
+
const uploadUrl = `${fileHandlerUrl}${separator}requestId=${requestId}`;
|
|
481
|
+
|
|
478
482
|
// Upload file
|
|
479
|
-
const uploadResponse = await axios.post(
|
|
483
|
+
const uploadResponse = await axios.post(uploadUrl, formData, {
|
|
480
484
|
headers: {
|
|
481
485
|
...formData.getHeaders()
|
|
482
486
|
},
|
package/package.json
CHANGED