wx2tg-puppet 1.0.9 → 1.1.0

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.
@@ -27,6 +27,8 @@ declare class ToolsApi {
27
27
  UploadFile(body: any): Axios.IPromise<Axios.AxiosXHR<unknown>>;
28
28
  /** 设置/删除代理IP */
29
29
  setproxy(body: any): Axios.IPromise<Axios.AxiosXHR<unknown>>;
30
+ /** CDN图片下载 */
31
+ CdnDownloadImage(body: any): Axios.IPromise<Axios.AxiosXHR<unknown>>;
30
32
  }
31
33
  export declare const toolsApi: ToolsApi;
32
34
  export {};
@@ -59,5 +59,9 @@ class ToolsApi {
59
59
  setproxy(body) {
60
60
  return axiosInstance_1.axiosInstance.post('/Tools/setproxy', body);
61
61
  }
62
+ /** CDN图片下载 */
63
+ CdnDownloadImage(body) {
64
+ return axiosInstance_1.axiosInstance.post('/Tools/CdnDownloadImage', body);
65
+ }
62
66
  }
63
67
  exports.toolsApi = new ToolsApi();
@@ -341,10 +341,29 @@ class Message {
341
341
  }
342
342
  toFileBox() {
343
343
  return __awaiter(this, void 0, void 0, function* () {
344
+ var _a;
344
345
  if (this.type() === MessageType_1.MessageType.Image) {
345
346
  const xml = this.msg.Content;
346
347
  const json = Message.getXmlToJson(xml);
347
348
  const config = yield config_service_1.configService.get();
349
+ // 优先使用 cdn 下载
350
+ const aeskey = json.msg.img.aeskey;
351
+ let url = json.msg.img.cdnbigimgurl;
352
+ if (!url) {
353
+ url = json.msg.img.cdnmidimgurl;
354
+ }
355
+ else if (!url) {
356
+ url = json.msg.img.cdnthumburl;
357
+ }
358
+ const cdnResp = yield ToolsApi_1.toolsApi.CdnDownloadImage({
359
+ "FileAesKey": aeskey,
360
+ "FileNo": url,
361
+ "Wxid": (config === null || config === void 0 ? void 0 : config.wxid) || ''
362
+ });
363
+ if (((_a = cdnResp === null || cdnResp === void 0 ? void 0 : cdnResp.data) === null || _a === void 0 ? void 0 : _a.Message) === '成功') {
364
+ const fileBox = file_box_1.FileBox.fromBase64(cdnResp.data.Data.Image, `${this.msg.MsgId}.png`);
365
+ return fileBox;
366
+ }
348
367
  const totalSize = parseInt(json.msg.img.length);
349
368
  // Get initial chunk size from first request
350
369
  const firstChunk = FileChunkHelper_1.FileChunkHelper.getChunk(totalSize, 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wx2tg-puppet",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
package/README.md DELETED
@@ -1,40 +0,0 @@
1
- # wx2tg-puppet
2
-
3
- 微信机器人核心库,可作为依赖被其他项目引入。
4
-
5
- ## 安装
6
-
7
- ```bash
8
- npm install /path/to/your/wx2tg-puppet
9
- # 或发布到 npm 后
10
- npm install wx2tg-puppet
11
- ```
12
-
13
- ## 使用示例
14
-
15
- ```ts
16
- import { WxBot } from 'wx2tg-puppet';
17
-
18
- const bot = new WxBot({
19
- baseUrl: 'http://your-api-url',
20
- databasePath: './db.sqlite',
21
- });
22
-
23
- bot.on('scan', (qrcode) => {
24
- // 展示二维码
25
- });
26
- bot.on('login', (user) => {
27
- // 登录成功
28
- });
29
- bot.on('message', (msg) => {
30
- // 收到消息
31
- });
32
-
33
- bot.start();
34
- ```
35
-
36
- ## 导出内容
37
- - WxBot
38
- - Contact
39
- - Room
40
- - Message