@juzi/wechaty-puppet-service 1.0.43 → 1.0.45
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/cjs/src/client/puppet-service.d.ts +3 -4
- package/dist/cjs/src/client/puppet-service.d.ts.map +1 -1
- package/dist/cjs/src/client/puppet-service.js +80 -198
- package/dist/cjs/src/client/puppet-service.js.map +1 -1
- package/dist/cjs/src/package-json.d.ts.map +1 -1
- package/dist/cjs/src/package-json.js +4 -3
- package/dist/cjs/src/package-json.js.map +1 -1
- package/dist/cjs/src/server/puppet-implementation.d.ts.map +1 -1
- package/dist/cjs/src/server/puppet-implementation.js +41 -127
- package/dist/cjs/src/server/puppet-implementation.js.map +1 -1
- package/dist/cjs/src/utils/pb-payload-helper.d.ts +5 -2
- package/dist/cjs/src/utils/pb-payload-helper.d.ts.map +1 -1
- package/dist/cjs/src/utils/pb-payload-helper.js +146 -1
- package/dist/cjs/src/utils/pb-payload-helper.js.map +1 -1
- package/dist/esm/src/client/puppet-service.d.ts +3 -4
- package/dist/esm/src/client/puppet-service.d.ts.map +1 -1
- package/dist/esm/src/client/puppet-service.js +78 -196
- package/dist/esm/src/client/puppet-service.js.map +1 -1
- package/dist/esm/src/package-json.d.ts.map +1 -1
- package/dist/esm/src/package-json.js +4 -3
- package/dist/esm/src/package-json.js.map +1 -1
- package/dist/esm/src/server/puppet-implementation.d.ts.map +1 -1
- package/dist/esm/src/server/puppet-implementation.js +40 -126
- package/dist/esm/src/server/puppet-implementation.js.map +1 -1
- package/dist/esm/src/utils/pb-payload-helper.d.ts +5 -2
- package/dist/esm/src/utils/pb-payload-helper.d.ts.map +1 -1
- package/dist/esm/src/utils/pb-payload-helper.js +120 -0
- package/dist/esm/src/utils/pb-payload-helper.js.map +1 -1
- package/package.json +4 -3
- package/src/client/puppet-service.ts +97 -214
- package/src/package-json.ts +4 -3
- package/src/server/puppet-implementation.ts +50 -144
- package/src/utils/pb-payload-helper.ts +119 -2
- package/dist/cjs/src/deprecated/chunk-pb.d.ts +0 -15
- package/dist/cjs/src/deprecated/chunk-pb.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/chunk-pb.js +0 -60
- package/dist/cjs/src/deprecated/chunk-pb.js.map +0 -1
- package/dist/cjs/src/deprecated/chunk-pb.spec.d.ts +0 -3
- package/dist/cjs/src/deprecated/chunk-pb.spec.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/chunk-pb.spec.js +0 -144
- package/dist/cjs/src/deprecated/chunk-pb.spec.js.map +0 -1
- package/dist/cjs/src/deprecated/conversation-id-file-box.d.ts +0 -21
- package/dist/cjs/src/deprecated/conversation-id-file-box.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/conversation-id-file-box.js +0 -43
- package/dist/cjs/src/deprecated/conversation-id-file-box.js.map +0 -1
- package/dist/cjs/src/deprecated/conversation-id-file-box.spec.d.ts +0 -3
- package/dist/cjs/src/deprecated/conversation-id-file-box.spec.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/conversation-id-file-box.spec.js +0 -94
- package/dist/cjs/src/deprecated/conversation-id-file-box.spec.js.map +0 -1
- package/dist/cjs/src/deprecated/file-box-chunk.d.ts +0 -14
- package/dist/cjs/src/deprecated/file-box-chunk.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/file-box-chunk.js +0 -67
- package/dist/cjs/src/deprecated/file-box-chunk.js.map +0 -1
- package/dist/cjs/src/deprecated/file-box-chunk.spec.d.ts +0 -3
- package/dist/cjs/src/deprecated/file-box-chunk.spec.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/file-box-chunk.spec.js +0 -134
- package/dist/cjs/src/deprecated/file-box-chunk.spec.js.map +0 -1
- package/dist/cjs/src/deprecated/file-box-pb.d.ts +0 -15
- package/dist/cjs/src/deprecated/file-box-pb.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/file-box-pb.js +0 -26
- package/dist/cjs/src/deprecated/file-box-pb.js.map +0 -1
- package/dist/cjs/src/deprecated/file-box-pb.spec.d.ts +0 -3
- package/dist/cjs/src/deprecated/file-box-pb.spec.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/file-box-pb.spec.js +0 -18
- package/dist/cjs/src/deprecated/file-box-pb.spec.js.map +0 -1
- package/dist/cjs/src/deprecated/file-box-pb.type.d.ts +0 -15
- package/dist/cjs/src/deprecated/file-box-pb.type.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/file-box-pb.type.js +0 -3
- package/dist/cjs/src/deprecated/file-box-pb.type.js.map +0 -1
- package/dist/cjs/src/deprecated/mod.d.ts +0 -3
- package/dist/cjs/src/deprecated/mod.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/mod.js +0 -10
- package/dist/cjs/src/deprecated/mod.js.map +0 -1
- package/dist/cjs/src/deprecated/next-data.d.ts +0 -7
- package/dist/cjs/src/deprecated/next-data.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/next-data.js +0 -26
- package/dist/cjs/src/deprecated/next-data.js.map +0 -1
- package/dist/cjs/src/deprecated/serialize-file-box.d.ts +0 -6
- package/dist/cjs/src/deprecated/serialize-file-box.d.ts.map +0 -1
- package/dist/cjs/src/deprecated/serialize-file-box.js +0 -22
- package/dist/cjs/src/deprecated/serialize-file-box.js.map +0 -1
- package/dist/esm/src/deprecated/chunk-pb.d.ts +0 -15
- package/dist/esm/src/deprecated/chunk-pb.d.ts.map +0 -1
- package/dist/esm/src/deprecated/chunk-pb.js +0 -56
- package/dist/esm/src/deprecated/chunk-pb.js.map +0 -1
- package/dist/esm/src/deprecated/chunk-pb.spec.d.ts +0 -3
- package/dist/esm/src/deprecated/chunk-pb.spec.d.ts.map +0 -1
- package/dist/esm/src/deprecated/chunk-pb.spec.js +0 -142
- package/dist/esm/src/deprecated/chunk-pb.spec.js.map +0 -1
- package/dist/esm/src/deprecated/conversation-id-file-box.d.ts +0 -21
- package/dist/esm/src/deprecated/conversation-id-file-box.d.ts.map +0 -1
- package/dist/esm/src/deprecated/conversation-id-file-box.js +0 -39
- package/dist/esm/src/deprecated/conversation-id-file-box.js.map +0 -1
- package/dist/esm/src/deprecated/conversation-id-file-box.spec.d.ts +0 -3
- package/dist/esm/src/deprecated/conversation-id-file-box.spec.d.ts.map +0 -1
- package/dist/esm/src/deprecated/conversation-id-file-box.spec.js +0 -92
- package/dist/esm/src/deprecated/conversation-id-file-box.spec.js.map +0 -1
- package/dist/esm/src/deprecated/file-box-chunk.d.ts +0 -14
- package/dist/esm/src/deprecated/file-box-chunk.d.ts.map +0 -1
- package/dist/esm/src/deprecated/file-box-chunk.js +0 -63
- package/dist/esm/src/deprecated/file-box-chunk.js.map +0 -1
- package/dist/esm/src/deprecated/file-box-chunk.spec.d.ts +0 -3
- package/dist/esm/src/deprecated/file-box-chunk.spec.d.ts.map +0 -1
- package/dist/esm/src/deprecated/file-box-chunk.spec.js +0 -132
- package/dist/esm/src/deprecated/file-box-chunk.spec.js.map +0 -1
- package/dist/esm/src/deprecated/file-box-pb.d.ts +0 -15
- package/dist/esm/src/deprecated/file-box-pb.d.ts.map +0 -1
- package/dist/esm/src/deprecated/file-box-pb.js +0 -22
- package/dist/esm/src/deprecated/file-box-pb.js.map +0 -1
- package/dist/esm/src/deprecated/file-box-pb.spec.d.ts +0 -3
- package/dist/esm/src/deprecated/file-box-pb.spec.d.ts.map +0 -1
- package/dist/esm/src/deprecated/file-box-pb.spec.js +0 -16
- package/dist/esm/src/deprecated/file-box-pb.spec.js.map +0 -1
- package/dist/esm/src/deprecated/file-box-pb.type.d.ts +0 -15
- package/dist/esm/src/deprecated/file-box-pb.type.d.ts.map +0 -1
- package/dist/esm/src/deprecated/file-box-pb.type.js +0 -2
- package/dist/esm/src/deprecated/file-box-pb.type.js.map +0 -1
- package/dist/esm/src/deprecated/mod.d.ts +0 -3
- package/dist/esm/src/deprecated/mod.d.ts.map +0 -1
- package/dist/esm/src/deprecated/mod.js +0 -3
- package/dist/esm/src/deprecated/mod.js.map +0 -1
- package/dist/esm/src/deprecated/next-data.d.ts +0 -7
- package/dist/esm/src/deprecated/next-data.d.ts.map +0 -1
- package/dist/esm/src/deprecated/next-data.js +0 -23
- package/dist/esm/src/deprecated/next-data.js.map +0 -1
- package/dist/esm/src/deprecated/serialize-file-box.d.ts +0 -6
- package/dist/esm/src/deprecated/serialize-file-box.d.ts.map +0 -1
- package/dist/esm/src/deprecated/serialize-file-box.js +0 -18
- package/dist/esm/src/deprecated/serialize-file-box.js.map +0 -1
- package/src/deprecated/chunk-pb.spec.ts +0 -210
- package/src/deprecated/chunk-pb.ts +0 -75
- package/src/deprecated/conversation-id-file-box.spec.ts +0 -131
- package/src/deprecated/conversation-id-file-box.ts +0 -72
- package/src/deprecated/file-box-chunk.spec.ts +0 -184
- package/src/deprecated/file-box-chunk.ts +0 -87
- package/src/deprecated/file-box-pb.spec.ts +0 -31
- package/src/deprecated/file-box-pb.ts +0 -41
- package/src/deprecated/file-box-pb.type.ts +0 -16
- package/src/deprecated/mod.ts +0 -8
- package/src/deprecated/next-data.ts +0 -35
- package/src/deprecated/serialize-file-box.ts +0 -24
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm
|
|
2
|
-
import { test } from 'tstest';
|
|
3
|
-
import { FileBox } from 'file-box';
|
|
4
|
-
import { puppet, } from '@juzi/wechaty-grpc';
|
|
5
|
-
import { packFileBoxToPb, unpackFileBoxFromPb, } from './file-box-pb.js';
|
|
6
|
-
test('packFileBoxToPb()', async (t) => {
|
|
7
|
-
const FILE_BOX_DATA = 'test';
|
|
8
|
-
const FILE_BOX_NAME = 'test.dat';
|
|
9
|
-
const fileBox = FileBox.fromBuffer(Buffer.from(FILE_BOX_DATA), FILE_BOX_NAME);
|
|
10
|
-
const pb = await packFileBoxToPb(puppet.MessageFileStreamResponse)(fileBox);
|
|
11
|
-
const restoredFileBox = await unpackFileBoxFromPb(pb);
|
|
12
|
-
t.ok(restoredFileBox instanceof FileBox, 'should get an instance of FileBOX');
|
|
13
|
-
t.equal(restoredFileBox.name, fileBox.name, 'should get the right file box name');
|
|
14
|
-
t.equal(await restoredFileBox.toBase64(), await fileBox.toBase64(), 'should get the right file box content');
|
|
15
|
-
});
|
|
16
|
-
//# sourceMappingURL=file-box-pb.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-box-pb.spec.js","sourceRoot":"","sources":["../../../../src/deprecated/file-box-pb.spec.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAElC,OAAO,EACL,MAAM,GACP,MAAsC,oBAAoB,CAAA;AAE3D,OAAO,EACL,eAAe,EACf,mBAAmB,GACpB,MAAkC,kBAAkB,CAAA;AAErD,IAAI,CAAC,mBAAmB,EAAE,KAAK,EAAC,CAAC,EAAC,EAAE;IAClC,MAAM,aAAa,GAAG,MAAM,CAAA;IAC5B,MAAM,aAAa,GAAG,UAAU,CAAA;IAEhC,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAChC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,EAC1B,aAAa,CACd,CAAA;IAED,MAAM,EAAE,GAAG,MAAM,eAAe,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC,OAAO,CAAC,CAAA;IAC3E,MAAM,eAAe,GAAG,MAAM,mBAAmB,CAAC,EAAE,CAAC,CAAA;IACrD,CAAC,CAAC,EAAE,CAAC,eAAe,YAAY,OAAO,EAAE,mCAAmC,CAAC,CAAA;IAE7E,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,oCAAoC,CAAC,CAAA;IACjF,CAAC,CAAC,KAAK,CAAC,MAAM,eAAe,CAAC,QAAQ,EAAE,EAAE,MAAM,OAAO,CAAC,QAAQ,EAAE,EAAE,uCAAuC,CAAC,CAAA;AAC9G,CAAC,CAAC,CAAA"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { puppet } from '@juzi/wechaty-grpc';
|
|
2
|
-
/**
|
|
3
|
-
* Any Protocol Buffer message that include a FileBoxChunk
|
|
4
|
-
*/
|
|
5
|
-
export interface FileBoxPb {
|
|
6
|
-
hasFileBoxChunk(): boolean;
|
|
7
|
-
getFileBoxChunk(): puppet.FileBoxChunk | undefined;
|
|
8
|
-
setFileBoxChunk(value?: puppet.FileBoxChunk): void;
|
|
9
|
-
}
|
|
10
|
-
export interface ConversationIdFileBoxPb extends FileBoxPb {
|
|
11
|
-
hasConversationId(): boolean;
|
|
12
|
-
getConversationId(): string;
|
|
13
|
-
setConversationId(value: string): void;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=file-box-pb.type.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-box-pb.type.d.ts","sourceRoot":"","sources":["../../../../src/deprecated/file-box-pb.type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAEhD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,eAAe,IAAI,OAAO,CAAA;IAC1B,eAAe,IAAI,MAAM,CAAC,YAAY,GAAG,SAAS,CAAA;IAClD,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,YAAY,GAAG,IAAI,CAAA;CACnD;AAED,MAAM,WAAW,uBAAwB,SAAQ,SAAS;IACxD,iBAAiB,IAAI,OAAO,CAAA;IAC5B,iBAAiB,IAAI,MAAM,CAAA;IAC3B,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CACvC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-box-pb.type.js","sourceRoot":"","sources":["../../../../src/deprecated/file-box-pb.type.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/deprecated/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,qCAAqC,GACtC,MAA8C,+BAA+B,CAAA;AAC9E,OAAO,EACL,eAAe,EACf,mBAAmB,GACpB,MAA8C,kBAAkB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../../src/deprecated/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,qCAAqC,GACtC,MAA8C,+BAA+B,CAAA;AAC9E,OAAO,EACL,eAAe,EACf,mBAAmB,GACpB,MAA8C,kBAAkB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"next-data.d.ts","sourceRoot":"","sources":["../../../../src/deprecated/next-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACT,MAAgB,wBAAwB,CAAA;AAQzC;;GAEG;AACH,iBAAe,QAAQ,CAAC,CAAC,EACvB,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,GAClB,OAAO,CAAC,CAAC,CAAC,CAeZ;AAED,OAAO,EACL,QAAQ,GACT,CAAA"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* windmemory(20201027): generating fileBox data in server side might take longer.
|
|
3
|
-
* Set to 60 sec to avoid unexpected timeout.
|
|
4
|
-
*/
|
|
5
|
-
const TIMEOUT = 60 * 1000;
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated Will be removed after Dec 31, 2022
|
|
8
|
-
*/
|
|
9
|
-
async function nextData(stream) {
|
|
10
|
-
const chunk = await new Promise((resolve, reject) => {
|
|
11
|
-
const timer = setTimeout(reject, TIMEOUT);
|
|
12
|
-
stream.once('data', chunk => {
|
|
13
|
-
stream.pause();
|
|
14
|
-
clearTimeout(timer);
|
|
15
|
-
resolve(chunk);
|
|
16
|
-
});
|
|
17
|
-
stream.once('error', reject);
|
|
18
|
-
});
|
|
19
|
-
stream.resume();
|
|
20
|
-
return chunk;
|
|
21
|
-
}
|
|
22
|
-
export { nextData, };
|
|
23
|
-
//# sourceMappingURL=next-data.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"next-data.js","sourceRoot":"","sources":["../../../../src/deprecated/next-data.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,OAAO,GAAG,EAAE,GAAG,IAAI,CAAA;AAEzB;;GAEG;AACH,KAAK,UAAU,QAAQ,CACrB,MAAmB;IAEnB,MAAM,KAAK,GAAG,MAAM,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrD,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACzC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE;YAC1B,MAAM,CAAC,KAAK,EAAE,CAAA;YACd,YAAY,CAAC,KAAK,CAAC,CAAA;YAEnB,OAAO,CAAC,KAAK,CAAC,CAAA;QAChB,CAAC,CAAC,CAAA;QACF,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAE9B,CAAC,CAAC,CAAA;IAEF,MAAM,CAAC,MAAM,EAAE,CAAA;IACf,OAAO,KAAK,CAAA;AACd,CAAC;AAED,OAAO,EACL,QAAQ,GACT,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialize-file-box.d.ts","sourceRoot":"","sources":["../../../../src/deprecated/serialize-file-box.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EACjB,MAA0B,UAAU,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,gBAAgB,YAAmB,gBAAgB,KAAG,QAAQ,MAAM,CAYhF,CAAA"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { FileBox, FileBoxType, } from 'file-box';
|
|
2
|
-
/**
|
|
3
|
-
* @deprecated Will be removed after Dec 31, 2022
|
|
4
|
-
*/
|
|
5
|
-
export const serializeFileBox = async (fileBox) => {
|
|
6
|
-
const serializableFileBoxTypes = [
|
|
7
|
-
FileBoxType.Base64,
|
|
8
|
-
FileBoxType.Url,
|
|
9
|
-
FileBoxType.QRCode,
|
|
10
|
-
];
|
|
11
|
-
if (serializableFileBoxTypes.includes(fileBox.type)) {
|
|
12
|
-
return JSON.stringify(fileBox);
|
|
13
|
-
}
|
|
14
|
-
const base64 = await fileBox.toBase64();
|
|
15
|
-
const name = fileBox.name;
|
|
16
|
-
return JSON.stringify(FileBox.fromBase64(base64, name));
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=serialize-file-box.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialize-file-box.js","sourceRoot":"","sources":["../../../../src/deprecated/serialize-file-box.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,WAAW,GACZ,MAA0B,UAAU,CAAA;AAKrC;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,OAAyB,EAAmB,EAAE;IACnF,MAAM,wBAAwB,GAAG;QAC/B,WAAW,CAAC,MAAM;QAClB,WAAW,CAAC,GAAG;QACf,WAAW,CAAC,MAAM;KACnB,CAAA;IACD,IAAI,wBAAwB,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACnD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;KAC/B;IACD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAA;IACvC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;IACzB,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAA;AACzD,CAAC,CAAA"}
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm
|
|
2
|
-
|
|
3
|
-
import { test } from 'tstest'
|
|
4
|
-
|
|
5
|
-
import { PassThrough } from 'stream'
|
|
6
|
-
|
|
7
|
-
import { FileBox } from 'file-box'
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
puppet,
|
|
11
|
-
} from '@juzi/wechaty-grpc'
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
unpackFileBoxFromChunk,
|
|
15
|
-
packFileBoxToChunk,
|
|
16
|
-
} from './file-box-chunk.js'
|
|
17
|
-
import {
|
|
18
|
-
unpackFileBoxChunkFromPb,
|
|
19
|
-
packFileBoxChunkToPb,
|
|
20
|
-
} from './chunk-pb.js'
|
|
21
|
-
|
|
22
|
-
test('packFileBoxChunk()', async t => {
|
|
23
|
-
const FILE_BOX_DATA = 'test'
|
|
24
|
-
const FILE_BOX_NAME = 'test.dat'
|
|
25
|
-
|
|
26
|
-
const fileBox = FileBox.fromBuffer(
|
|
27
|
-
Buffer.from(FILE_BOX_DATA),
|
|
28
|
-
FILE_BOX_NAME,
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
const chunkStream = await packFileBoxToChunk(fileBox)
|
|
32
|
-
const pbStream = await packFileBoxChunkToPb(puppet.MessageFileStreamResponse)(chunkStream)
|
|
33
|
-
|
|
34
|
-
let name = ''
|
|
35
|
-
let buffer = ''
|
|
36
|
-
pbStream.on('data', (data: puppet.MessageFileStreamResponse) => {
|
|
37
|
-
if (data.hasFileBoxChunk()) {
|
|
38
|
-
const fileBoxChunk = data.getFileBoxChunk()
|
|
39
|
-
if (fileBoxChunk!.hasData()) {
|
|
40
|
-
buffer += fileBoxChunk!.getData()
|
|
41
|
-
} else if (fileBoxChunk!.hasName()) {
|
|
42
|
-
name = fileBoxChunk!.getName()
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
await new Promise(resolve => chunkStream.on('end', resolve))
|
|
48
|
-
t.equal(name, FILE_BOX_NAME, 'should get file box name')
|
|
49
|
-
t.equal(buffer, FILE_BOX_DATA, 'should get file box data')
|
|
50
|
-
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
test('unpackFileBoxChunkFromPb()', async t => {
|
|
54
|
-
const FILE_BOX_DATA = 'test'
|
|
55
|
-
const FILE_BOX_NAME = 'test.dat'
|
|
56
|
-
|
|
57
|
-
const fileBox = FileBox.fromBuffer(
|
|
58
|
-
Buffer.from(FILE_BOX_DATA),
|
|
59
|
-
FILE_BOX_NAME,
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
const chunkStream = await packFileBoxToChunk(fileBox)
|
|
63
|
-
const request = new puppet.MessageSendFileStreamRequest()
|
|
64
|
-
|
|
65
|
-
const packedStream = new PassThrough({ objectMode: true })
|
|
66
|
-
|
|
67
|
-
chunkStream.on('data', (data: puppet.FileBoxChunk) => {
|
|
68
|
-
request.setFileBoxChunk(data)
|
|
69
|
-
packedStream.write(request)
|
|
70
|
-
}).on('end', () => {
|
|
71
|
-
packedStream.end()
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
const outputChunkStream = unpackFileBoxChunkFromPb(packedStream)
|
|
75
|
-
const outputFileBox = await unpackFileBoxFromChunk(outputChunkStream)
|
|
76
|
-
|
|
77
|
-
t.equal((await outputFileBox.toBuffer()).toString(), FILE_BOX_DATA, 'should get file box data')
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
test('packFileBoxChunk() <-> unpackFileBoxChunkFromPb()', async t => {
|
|
81
|
-
const FILE_BOX_DATA = 'test'
|
|
82
|
-
const FILE_BOX_NAME = 'test.dat'
|
|
83
|
-
|
|
84
|
-
const fileBox = FileBox.fromBuffer(
|
|
85
|
-
Buffer.from(FILE_BOX_DATA),
|
|
86
|
-
FILE_BOX_NAME,
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
const chunkStream = await packFileBoxToChunk(fileBox)
|
|
90
|
-
const packedStream = packFileBoxChunkToPb(puppet.MessageFileStreamResponse)(chunkStream)
|
|
91
|
-
|
|
92
|
-
const unpackedStream = unpackFileBoxChunkFromPb(packedStream)
|
|
93
|
-
const restoredBox = await unpackFileBoxFromChunk(unpackedStream)
|
|
94
|
-
t.equal(fileBox.name, restoredBox.name, 'should be same name')
|
|
95
|
-
|
|
96
|
-
const EXPECTED_BASE64 = await fileBox.toBase64()
|
|
97
|
-
const actualBase64 = await restoredBox.toBase64()
|
|
98
|
-
|
|
99
|
-
t.equal(EXPECTED_BASE64, actualBase64, 'should be same content')
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
test('packFileBoxChunk(): should not throw if no read on the stream', async t => {
|
|
103
|
-
|
|
104
|
-
t.plan(1)
|
|
105
|
-
const stream = await getTestChunkStream({})
|
|
106
|
-
let outStream
|
|
107
|
-
try {
|
|
108
|
-
outStream = packFileBoxChunkToPb(puppet.MessageFileStreamResponse)(stream)
|
|
109
|
-
} catch (e) {
|
|
110
|
-
t.ok((e as Error).message)
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
outStream.on('error', _ => { /* Do nothing */ })
|
|
114
|
-
t.pass()
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
test('packFileBoxChunk(): should emit error in the output stream', async t => {
|
|
118
|
-
const EXPECTED_MESSAGE = 'test emit error'
|
|
119
|
-
|
|
120
|
-
const stream = await getTestChunkStream({ errorMessage: EXPECTED_MESSAGE })
|
|
121
|
-
const outStream = packFileBoxChunkToPb(puppet.MessageFileStreamResponse)(stream)
|
|
122
|
-
|
|
123
|
-
const error = await new Promise<Error>(resolve => outStream.on('error', resolve))
|
|
124
|
-
// await new Promise(resolve => outStream.on('end', resolve))
|
|
125
|
-
t.equal(error.message, EXPECTED_MESSAGE, 'should emit error message')
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
test('unpackFileBoxChunkFromPb(): should not throw if no read on the stream', async t => {
|
|
129
|
-
|
|
130
|
-
t.plan(1)
|
|
131
|
-
const stream = await getTestPackedStream({})
|
|
132
|
-
let outStream
|
|
133
|
-
try {
|
|
134
|
-
outStream = unpackFileBoxChunkFromPb(stream)
|
|
135
|
-
t.pass('should no rejection')
|
|
136
|
-
} catch (e) {
|
|
137
|
-
t.fail((e as Error).message)
|
|
138
|
-
return
|
|
139
|
-
}
|
|
140
|
-
outStream.on('error', _ => { /* Do nothing */ })
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
test('unpackFileBoxChunkFromPb(): should emit error in the output stream', async t => {
|
|
144
|
-
|
|
145
|
-
const errorMessage = 'test emit error'
|
|
146
|
-
const stream = await getTestPackedStream({ errorMessage })
|
|
147
|
-
|
|
148
|
-
const outStream = packFileBoxChunkToPb(puppet.MessageFileStreamResponse)(stream)
|
|
149
|
-
|
|
150
|
-
try {
|
|
151
|
-
await new Promise((resolve, reject) => {
|
|
152
|
-
outStream.on('error', reject)
|
|
153
|
-
outStream.on('end', resolve)
|
|
154
|
-
})
|
|
155
|
-
t.fail('should reject the promise')
|
|
156
|
-
} catch (e) {
|
|
157
|
-
t.equal((e as Error).message, errorMessage, 'should get the expected rejection error message')
|
|
158
|
-
}
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
async function getTestChunkStream (options: {
|
|
162
|
-
errorMessage?: string,
|
|
163
|
-
}) {
|
|
164
|
-
const { errorMessage } = options
|
|
165
|
-
|
|
166
|
-
const FILE_BOX_DATA = 'test'
|
|
167
|
-
const FILE_BOX_NAME = 'test.dat'
|
|
168
|
-
|
|
169
|
-
const fileBox = FileBox.fromBuffer(
|
|
170
|
-
Buffer.from(FILE_BOX_DATA),
|
|
171
|
-
FILE_BOX_NAME,
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
const chunkStream = await packFileBoxToChunk(fileBox)
|
|
175
|
-
setImmediate(() => {
|
|
176
|
-
chunkStream.emit('error', new Error(errorMessage))
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
return chunkStream
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async function getTestPackedStream (options: {
|
|
183
|
-
errorMessage?: string,
|
|
184
|
-
}) {
|
|
185
|
-
const { errorMessage } = options
|
|
186
|
-
|
|
187
|
-
const FILE_BOX_DATA = 'test'
|
|
188
|
-
const FILE_BOX_NAME = 'test.dat'
|
|
189
|
-
|
|
190
|
-
const fileBox = FileBox.fromBuffer(
|
|
191
|
-
Buffer.from(FILE_BOX_DATA),
|
|
192
|
-
FILE_BOX_NAME,
|
|
193
|
-
)
|
|
194
|
-
|
|
195
|
-
const chunkStream = await packFileBoxToChunk(fileBox)
|
|
196
|
-
const packedStream = new PassThrough({ objectMode: true })
|
|
197
|
-
chunkStream.on('data', d => {
|
|
198
|
-
const packedChunk = new puppet.MessageFileStreamResponse()
|
|
199
|
-
packedChunk.setFileBoxChunk(d)
|
|
200
|
-
packedStream.write(packedChunk)
|
|
201
|
-
}).on('error', e => {
|
|
202
|
-
packedStream.emit('error', e)
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
setImmediate(() => {
|
|
206
|
-
chunkStream.emit('error', new Error(errorMessage))
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
return packedStream
|
|
210
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { puppet } from '@juzi/wechaty-grpc'
|
|
2
|
-
import { Readable, Transform } from 'stronger-typed-streams'
|
|
3
|
-
import { PassThrough } from 'stream'
|
|
4
|
-
|
|
5
|
-
import type { FileBoxPb } from './file-box-pb.type.js'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Wrap FileBoxChunk
|
|
9
|
-
* @deprecated Will be removed after Dec 31, 2022
|
|
10
|
-
*/
|
|
11
|
-
const encoder = <T extends FileBoxPb>(
|
|
12
|
-
PbConstructor: { new(): T },
|
|
13
|
-
) => new Transform<puppet.FileBoxChunk, T>({
|
|
14
|
-
objectMode: true,
|
|
15
|
-
transform: (chunk: puppet.FileBoxChunk, _: any, callback: (error: Error | null, data: T) => void) => {
|
|
16
|
-
const message = new PbConstructor()
|
|
17
|
-
message.setFileBoxChunk(chunk)
|
|
18
|
-
callback(null, message)
|
|
19
|
-
},
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @deprecated Will be removed after Dec 31, 2022
|
|
24
|
-
*/
|
|
25
|
-
function packFileBoxChunkToPb<T extends FileBoxPb> (
|
|
26
|
-
PbConstructor: { new(): T },
|
|
27
|
-
) {
|
|
28
|
-
return (stream: Readable<puppet.FileBoxChunk>): Readable<T> => {
|
|
29
|
-
const outStream = new PassThrough({ objectMode: true })
|
|
30
|
-
const encodedStream = stream.pipe(encoder(PbConstructor))
|
|
31
|
-
|
|
32
|
-
stream.on('error', e => outStream.emit('error', e))
|
|
33
|
-
encodedStream.on('error', e => outStream.emit('error', e))
|
|
34
|
-
|
|
35
|
-
encodedStream.pipe(outStream)
|
|
36
|
-
return outStream
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Unwrap FileBoxChunk
|
|
42
|
-
* @deprecated Will be removed after Dec 31, 2022
|
|
43
|
-
*/
|
|
44
|
-
const decoder = <T extends FileBoxPb>() => new Transform<T, puppet.FileBoxChunk>({
|
|
45
|
-
objectMode: true,
|
|
46
|
-
transform: (chunk: T, _: any, callback: (error: Error | null, data?: puppet.FileBoxChunk) => void) => {
|
|
47
|
-
const fileBoxChunk = chunk.getFileBoxChunk()
|
|
48
|
-
if (!fileBoxChunk) {
|
|
49
|
-
callback(new Error('No FileBoxChunk'))
|
|
50
|
-
} else {
|
|
51
|
-
callback(null, fileBoxChunk)
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @deprecated Will be removed after Dec 31, 2022
|
|
58
|
-
*/
|
|
59
|
-
function unpackFileBoxChunkFromPb<T extends FileBoxPb> (
|
|
60
|
-
stream: Readable<T>,
|
|
61
|
-
): Readable<puppet.FileBoxChunk> {
|
|
62
|
-
const outStream = new PassThrough({ objectMode: true })
|
|
63
|
-
const decodedStream = stream.pipe(decoder())
|
|
64
|
-
|
|
65
|
-
stream.on('error', e => outStream.emit('error', e))
|
|
66
|
-
decodedStream.on('error', e => outStream.emit('error', e))
|
|
67
|
-
|
|
68
|
-
decodedStream.pipe(outStream)
|
|
69
|
-
return outStream
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export {
|
|
73
|
-
packFileBoxChunkToPb,
|
|
74
|
-
unpackFileBoxChunkFromPb,
|
|
75
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env -S node --no-warnings --loader ts-node/esm
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Wechaty Chatbot SDK - https://github.com/wechaty/wechaty
|
|
5
|
-
*
|
|
6
|
-
* @copyright 2016 Huan LI (李卓桓) <https://github.com/huan>, and
|
|
7
|
-
* Wechaty Contributors <https://github.com/wechaty>.
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
import {
|
|
23
|
-
puppet,
|
|
24
|
-
} from '@juzi/wechaty-grpc'
|
|
25
|
-
|
|
26
|
-
import { test } from 'tstest'
|
|
27
|
-
import { PassThrough } from 'stream'
|
|
28
|
-
import { FileBox } from 'file-box'
|
|
29
|
-
|
|
30
|
-
import { nextData } from './next-data.js'
|
|
31
|
-
import {
|
|
32
|
-
packConversationIdFileBoxToPb,
|
|
33
|
-
unpackConversationIdFileBoxArgsFromPb,
|
|
34
|
-
} from './conversation-id-file-box.js'
|
|
35
|
-
|
|
36
|
-
test('unpackConversationIdFileBoxArgsFromPb()', async t => {
|
|
37
|
-
const FILE_BOX_DATA = 'test'
|
|
38
|
-
const FILE_BOX_NAME = 'test.dat'
|
|
39
|
-
const CONVERSATION_ID = 'conversation_id'
|
|
40
|
-
|
|
41
|
-
const fileBox = FileBox.fromBuffer(
|
|
42
|
-
Buffer.from(FILE_BOX_DATA),
|
|
43
|
-
FILE_BOX_NAME,
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
const stream = new PassThrough({ objectMode: true })
|
|
47
|
-
|
|
48
|
-
const req1 = new puppet.MessageSendFileStreamRequest()
|
|
49
|
-
req1.setConversationId(CONVERSATION_ID)
|
|
50
|
-
stream.write(req1)
|
|
51
|
-
|
|
52
|
-
const req2 = new puppet.MessageSendFileStreamRequest()
|
|
53
|
-
const chunk1 = new puppet.FileBoxChunk()
|
|
54
|
-
chunk1.setName(fileBox.name)
|
|
55
|
-
req2.setFileBoxChunk(chunk1)
|
|
56
|
-
stream.write(req2)
|
|
57
|
-
|
|
58
|
-
const fileBoxStream = await fileBox.toStream()
|
|
59
|
-
fileBoxStream.on('data', chunk => {
|
|
60
|
-
const fileBoxChunk = new puppet.FileBoxChunk()
|
|
61
|
-
fileBoxChunk.setData(chunk)
|
|
62
|
-
const req3 = new puppet.MessageSendFileStreamRequest()
|
|
63
|
-
req3.setFileBoxChunk(fileBoxChunk)
|
|
64
|
-
stream.write(req3)
|
|
65
|
-
})
|
|
66
|
-
fileBoxStream.on('end', () => stream.end())
|
|
67
|
-
|
|
68
|
-
const args = await unpackConversationIdFileBoxArgsFromPb(stream)
|
|
69
|
-
const data = (await args.fileBox.toBuffer()).toString()
|
|
70
|
-
|
|
71
|
-
t.equal(args.conversationId, CONVERSATION_ID, 'should get conversation id')
|
|
72
|
-
t.equal(args.fileBox.name, FILE_BOX_NAME, 'should get file box name')
|
|
73
|
-
t.equal(data, FILE_BOX_DATA, 'should get file box data')
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
test('packConversationIdFileBoxToPb()', async t => {
|
|
77
|
-
const FILE_BOX_DATA = 'test'
|
|
78
|
-
const FILE_BOX_NAME = 'test.dat'
|
|
79
|
-
const CONVERSATION_ID = 'conv_id'
|
|
80
|
-
|
|
81
|
-
const fileBox = FileBox.fromBuffer(
|
|
82
|
-
Buffer.from(FILE_BOX_DATA),
|
|
83
|
-
FILE_BOX_NAME,
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
const stream = await packConversationIdFileBoxToPb(puppet.MessageSendFileStreamRequest)(
|
|
87
|
-
CONVERSATION_ID,
|
|
88
|
-
fileBox,
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
const data1 = await nextData(stream)
|
|
92
|
-
t.equal(data1.getConversationId(), CONVERSATION_ID, 'match conversation id')
|
|
93
|
-
|
|
94
|
-
const data2 = await nextData(stream)
|
|
95
|
-
t.ok(data2.hasFileBoxChunk(), 'has file box chunk')
|
|
96
|
-
t.ok(data2.getFileBoxChunk()!.hasName(), 'has file box name')
|
|
97
|
-
t.equal(data2.getFileBoxChunk()!.getName(), FILE_BOX_NAME, 'match file box name')
|
|
98
|
-
|
|
99
|
-
let data = ''
|
|
100
|
-
stream.on('data', (chunk: puppet.MessageSendFileStreamRequest) => {
|
|
101
|
-
if (!chunk.hasFileBoxChunk()) {
|
|
102
|
-
throw new Error('no file box chunk')
|
|
103
|
-
}
|
|
104
|
-
if (!chunk.getFileBoxChunk()!.hasData()) {
|
|
105
|
-
throw new Error('no file box chunk data')
|
|
106
|
-
}
|
|
107
|
-
data += chunk.getFileBoxChunk()!.getData()
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
await new Promise(resolve => stream.on('end', resolve))
|
|
111
|
-
|
|
112
|
-
t.equal(data.toString(), FILE_BOX_DATA, 'should get file box data')
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
test('unpackConversationIdFileBoxArgsFromPb() <-> packConversationIdFileBoxToPb()', async t => {
|
|
116
|
-
const FILE_BOX_DATA = 'test'
|
|
117
|
-
const FILE_BOX_NAME = 'test.dat'
|
|
118
|
-
const CONVERSATION_ID = 'conv_id'
|
|
119
|
-
|
|
120
|
-
const fileBox = FileBox.fromBuffer(
|
|
121
|
-
Buffer.from(FILE_BOX_DATA),
|
|
122
|
-
FILE_BOX_NAME,
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
const stream = await packConversationIdFileBoxToPb(puppet.MessageSendFileStreamRequest)(CONVERSATION_ID, fileBox)
|
|
126
|
-
const args = await unpackConversationIdFileBoxArgsFromPb(stream)
|
|
127
|
-
|
|
128
|
-
t.equal(args.conversationId, CONVERSATION_ID, 'should match conversation id')
|
|
129
|
-
t.equal(args.fileBox.name, FILE_BOX_NAME, 'should be same name')
|
|
130
|
-
t.equal((await args.fileBox.toBuffer()).toString(), FILE_BOX_DATA, 'should be same content')
|
|
131
|
-
})
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
FileBoxInterface,
|
|
3
|
-
} from 'file-box'
|
|
4
|
-
import { PassThrough } from 'stream'
|
|
5
|
-
import type { Readable } from 'stronger-typed-streams'
|
|
6
|
-
|
|
7
|
-
import { nextData } from './next-data.js'
|
|
8
|
-
import {
|
|
9
|
-
packFileBoxToPb,
|
|
10
|
-
unpackFileBoxFromPb,
|
|
11
|
-
} from './file-box-pb.js'
|
|
12
|
-
import type { ConversationIdFileBoxPb } from './file-box-pb.type.js'
|
|
13
|
-
|
|
14
|
-
interface ConversationIdFileBoxArgs {
|
|
15
|
-
conversationId: string,
|
|
16
|
-
fileBox: FileBoxInterface,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* MessageSendFileStreamRequest to Args
|
|
21
|
-
* @deprecated Will be removed after Dec 31, 2022
|
|
22
|
-
*/
|
|
23
|
-
async function unpackConversationIdFileBoxArgsFromPb (
|
|
24
|
-
stream: Readable<ConversationIdFileBoxPb>,
|
|
25
|
-
): Promise<ConversationIdFileBoxArgs> {
|
|
26
|
-
const chunk = await nextData(stream)
|
|
27
|
-
if (!chunk.hasConversationId()) {
|
|
28
|
-
throw new Error('no conversation id')
|
|
29
|
-
}
|
|
30
|
-
const conversationId = chunk.getConversationId()
|
|
31
|
-
|
|
32
|
-
// unpackFileBoxFromChunk(unpackFileBoxChunkFromPb(stream))
|
|
33
|
-
const fileBox = await unpackFileBoxFromPb(stream)
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
conversationId,
|
|
37
|
-
fileBox,
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Args to MessageSendFileStreamRequest
|
|
43
|
-
* @deprecated Will be removed after Dec 31, 2022
|
|
44
|
-
*/
|
|
45
|
-
function packConversationIdFileBoxToPb<T extends ConversationIdFileBoxPb> (
|
|
46
|
-
PbConstructor: { new(): T },
|
|
47
|
-
) {
|
|
48
|
-
return async (
|
|
49
|
-
conversationId: string,
|
|
50
|
-
fileBox: FileBoxInterface,
|
|
51
|
-
): Promise<
|
|
52
|
-
Readable<T>
|
|
53
|
-
> => {
|
|
54
|
-
const stream = new PassThrough({ objectMode: true })
|
|
55
|
-
|
|
56
|
-
const first = new PbConstructor()
|
|
57
|
-
first.setConversationId(conversationId)
|
|
58
|
-
stream.write(first)
|
|
59
|
-
|
|
60
|
-
// const fileBoxChunkStream = await packFileBoxToChunk(fileBox)
|
|
61
|
-
// packFileBoxChunkToPb(MessageSendFileStreamRequest)(fileBoxChunkStream)
|
|
62
|
-
const pbStream = await packFileBoxToPb(PbConstructor)(fileBox)
|
|
63
|
-
pbStream.pipe(stream)
|
|
64
|
-
|
|
65
|
-
return stream
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export {
|
|
70
|
-
unpackConversationIdFileBoxArgsFromPb,
|
|
71
|
-
packConversationIdFileBoxToPb,
|
|
72
|
-
}
|