wechat-mp-controller 0.2.1 → 0.3.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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LaunchOptions } from 'puppeteer-core';
2
- import { SubmitAuditFormType } from './type';
2
+ import { SubmitAuditOptions } from './type';
3
3
  export type WeChatMpControllerOptions = Pick<LaunchOptions, 'headless' | 'userDataDir'>;
4
4
  export declare class WeChatMpController {
5
5
  static create(options?: WeChatMpControllerOptions): Promise<Controller>;
@@ -36,11 +36,5 @@ export declare class Controller {
36
36
  isExperience: boolean;
37
37
  }[];
38
38
  }>;
39
- submitAudit(options: {
40
- formData: SubmitAuditFormType;
41
- uploader: {
42
- name: string;
43
- openId: string;
44
- };
45
- }): Promise<void>;
39
+ submitAudit(options: SubmitAuditOptions): Promise<void>;
46
40
  }
package/dist/index.js CHANGED
@@ -116,7 +116,8 @@ export class Controller {
116
116
  }
117
117
  const {
118
118
  formData,
119
- uploader
119
+ uploader,
120
+ onUpload
120
121
  } = options;
121
122
  const searchParams = new URLSearchParams({
122
123
  action: 'get_class',
@@ -132,11 +133,33 @@ export class Controller {
132
133
  }
133
134
  if (formData.imageUrls?.length || formData.videoUrl) {
134
135
  const [imageUploader, videoUploader] = await this.page.$$('.webuploader-container input');
136
+ const uploadResponseHandles = [];
135
137
  if (formData.imageUrls?.length) {
136
- await imageUploader.uploadFile(...formData.imageUrls);
138
+ for (let A = 0; A < formData.imageUrls.length; ++A) {
139
+ await imageUploader.uploadFile(formData.imageUrls[A]);
140
+ uploadResponseHandles.push(this.page.waitForResponse(res => {
141
+ return res.url().includes('https://mp.weixin.qq.com/cgi-bin/filetransfer');
142
+ }).then(response => {
143
+ return onUpload?.({
144
+ filePath: formData.imageUrls[A],
145
+ response
146
+ });
147
+ }));
148
+ }
137
149
  }
138
150
  if (formData.videoUrl) {
139
151
  await videoUploader.uploadFile(formData.videoUrl);
152
+ uploadResponseHandles.push(this.page.waitForResponse(res => {
153
+ return res.url().includes('https://mp.weixin.qq.com/cgi-bin/filetransfer');
154
+ }).then(response => {
155
+ return onUpload?.({
156
+ filePath: formData.videoUrl,
157
+ response
158
+ });
159
+ }));
160
+ }
161
+ if (uploadResponseHandles.length) {
162
+ await Promise.all(uploadResponseHandles);
140
163
  }
141
164
  }
142
165
  await this.page.locator('.btn.btn_primary[data-msgid="提交审核"]').click();
package/dist/type.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { HTTPResponse } from 'puppeteer-core';
1
2
  export type VersionInfo = {
2
3
  uploader: {
3
4
  name: string;
@@ -64,3 +65,14 @@ export type SubmitAuditFormType = {
64
65
  imageUrls?: string[];
65
66
  videoUrl?: string;
66
67
  };
68
+ export type SubmitAuditOptions = {
69
+ formData: SubmitAuditFormType;
70
+ uploader: {
71
+ name: string;
72
+ openId: string;
73
+ };
74
+ onUpload?: (data: {
75
+ filePath: string;
76
+ response: HTTPResponse;
77
+ }) => Promise<void>;
78
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechat-mp-controller",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "license": "MIT",