[bug] Properly returns Map nested values in process data
This commit is contained in:
parent
28db1ae925
commit
c630aa8079
@ -1295,7 +1295,7 @@ export class Service {
|
||||
if (clear) {
|
||||
// deserialize the result to get the actual data
|
||||
const decoded = wasm.decode_value(clear);
|
||||
return decoded;
|
||||
return this.convertMapsToObjects(decoded);
|
||||
} else {
|
||||
throw new Error('decrypt_data returned null');
|
||||
}
|
||||
@ -1310,13 +1310,49 @@ export class Service {
|
||||
|
||||
decodeValue(value: number[]): any | null {
|
||||
try {
|
||||
return wasm.decode_value(new Uint8Array(value));
|
||||
const decoded = wasm.decode_value(new Uint8Array(value));
|
||||
return this.convertMapsToObjects(decoded);
|
||||
} catch (e) {
|
||||
console.error(`Failed to decode value: ${e}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convertit récursivement les Map en objets sérialisables
|
||||
*/
|
||||
private convertMapsToObjects(obj: any): any {
|
||||
if (obj === null || obj === undefined) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (obj instanceof Map) {
|
||||
const result: any = {};
|
||||
for (const [key, value] of obj.entries()) {
|
||||
result[key] = this.convertMapsToObjects(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (obj instanceof Set) {
|
||||
return Array.from(obj).map(item => this.convertMapsToObjects(item));
|
||||
}
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(item => this.convertMapsToObjects(item));
|
||||
}
|
||||
|
||||
if (typeof obj === 'object') {
|
||||
const result: any = {};
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
result[key] = this.convertMapsToObjects(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
public async updateDevice(): Promise<void> {
|
||||
let myPairingProcessId: string;
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user