createProcess split json and binary data and encode them separately
This commit is contained in:
parent
0f0b5d1af3
commit
f42aca7eb9
@ -301,6 +301,30 @@ export default class Services {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isFileBlob(value: any): value is { type: string, data: Uint8Array } {
|
||||||
|
return (
|
||||||
|
typeof value === 'object' &&
|
||||||
|
value !== null &&
|
||||||
|
typeof value.type === 'string' &&
|
||||||
|
value.data instanceof Uint8Array
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private splitData(obj: Record<string, any>) {
|
||||||
|
const jsonCompatibleData: Record<string, any> = {};
|
||||||
|
const binaryData: Record<string, { type: string; data: Uint8Array }> = {};
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(obj)) {
|
||||||
|
if (this.isFileBlob(value)) {
|
||||||
|
binaryData[key] = value;
|
||||||
|
} else {
|
||||||
|
jsonCompatibleData[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { jsonCompatibleData, binaryData };
|
||||||
|
}
|
||||||
|
|
||||||
public async createProcess(
|
public async createProcess(
|
||||||
privateData: Record<string, any>,
|
privateData: Record<string, any>,
|
||||||
publicData: Record<string, any>,
|
publicData: Record<string, any>,
|
||||||
@ -309,8 +333,19 @@ export default class Services {
|
|||||||
const relayAddress = this.getAllRelays()[0]['spAddress'];
|
const relayAddress = this.getAllRelays()[0]['spAddress'];
|
||||||
const feeRate = 1;
|
const feeRate = 1;
|
||||||
|
|
||||||
const encodedPrivateData = this.sdkClient.encode_pcd(privateData);
|
// We can't encode files as the rest because Uint8Array is not valid json
|
||||||
const encodedPublicData = this.sdkClient.encode_pcd(publicData);
|
// So we first take them apart and we will encode them separately and put them back in the right object
|
||||||
|
// TODO encoding of relatively large binaries (=> 1M) is a bit long now and blocking
|
||||||
|
const privateSplitData = this.splitData(privateData);
|
||||||
|
const publicSplitData = this.splitData(publicData);
|
||||||
|
const encodedPrivateData = {
|
||||||
|
...this.sdkClient.encode_json(privateSplitData.jsonCompatibleData),
|
||||||
|
...this.sdkClient.encode_binary(privateSplitData.binaryData)
|
||||||
|
};
|
||||||
|
const encodedPublicData = {
|
||||||
|
...this.sdkClient.encode_json(publicSplitData.jsonCompatibleData),
|
||||||
|
...this.sdkClient.encode_binary(publicSplitData.binaryData)
|
||||||
|
};
|
||||||
|
|
||||||
let members: Set<Member> = new Set();
|
let members: Set<Member> = new Set();
|
||||||
for (const role of Object.values(roles!)) {
|
for (const role of Object.values(roles!)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user