s3db.js 7.4.0 → 7.4.1
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/s3db.cjs.js +30 -2
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.es.js +30 -2
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +30 -2
- package/dist/s3db.iife.min.js +1 -1
- package/package.json +1 -1
- package/src/client.class.js +41 -1
package/package.json
CHANGED
package/src/client.class.js
CHANGED
|
@@ -103,7 +103,17 @@ export class Client extends EventEmitter {
|
|
|
103
103
|
for (const [k, v] of Object.entries(metadata)) {
|
|
104
104
|
// Ensure key is a valid string and value is a string
|
|
105
105
|
const validKey = String(k).replace(/[^a-zA-Z0-9\-_]/g, '_');
|
|
106
|
-
|
|
106
|
+
const stringValue = String(v);
|
|
107
|
+
|
|
108
|
+
// Check if value contains non-ASCII characters that might be corrupted by HTTP headers
|
|
109
|
+
const hasSpecialChars = /[^\x00-\x7F]/.test(stringValue);
|
|
110
|
+
|
|
111
|
+
if (hasSpecialChars) {
|
|
112
|
+
// Encode as base64 without prefix - we'll detect it intelligently on read
|
|
113
|
+
stringMetadata[validKey] = Buffer.from(stringValue, 'utf8').toString('base64');
|
|
114
|
+
} else {
|
|
115
|
+
stringMetadata[validKey] = stringValue;
|
|
116
|
+
}
|
|
107
117
|
}
|
|
108
118
|
}
|
|
109
119
|
|
|
@@ -141,9 +151,39 @@ export class Client extends EventEmitter {
|
|
|
141
151
|
Bucket: this.config.bucket,
|
|
142
152
|
Key: keyPrefix ? path.join(keyPrefix, key) : key,
|
|
143
153
|
};
|
|
154
|
+
|
|
144
155
|
let response, error;
|
|
145
156
|
try {
|
|
146
157
|
response = await this.sendCommand(new GetObjectCommand(options));
|
|
158
|
+
|
|
159
|
+
// Smart decode: try to detect base64-encoded UTF-8 values without prefix
|
|
160
|
+
if (response.Metadata) {
|
|
161
|
+
const decodedMetadata = {};
|
|
162
|
+
for (const [key, value] of Object.entries(response.Metadata)) {
|
|
163
|
+
if (typeof value === 'string') {
|
|
164
|
+
// Try to decode as base64 and check if it's valid UTF-8 with special chars
|
|
165
|
+
try {
|
|
166
|
+
const decoded = Buffer.from(value, 'base64').toString('utf8');
|
|
167
|
+
// Check if decoded string is different from original and contains non-ASCII chars
|
|
168
|
+
const hasSpecialChars = /[^\x00-\x7F]/.test(decoded);
|
|
169
|
+
const isValidBase64 = Buffer.from(decoded, 'utf8').toString('base64') === value;
|
|
170
|
+
|
|
171
|
+
if (isValidBase64 && hasSpecialChars && decoded !== value) {
|
|
172
|
+
decodedMetadata[key] = decoded;
|
|
173
|
+
} else {
|
|
174
|
+
decodedMetadata[key] = value;
|
|
175
|
+
}
|
|
176
|
+
} catch (decodeError) {
|
|
177
|
+
// If decode fails, use original value
|
|
178
|
+
decodedMetadata[key] = value;
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
decodedMetadata[key] = value;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
response.Metadata = decodedMetadata;
|
|
185
|
+
}
|
|
186
|
+
|
|
147
187
|
return response;
|
|
148
188
|
} catch (err) {
|
|
149
189
|
error = err;
|