From 5326c62f063fdfedddde944f0c356cc975352f7b Mon Sep 17 00:00:00 2001 From: CaoMeiYouRen <996881204@qq.com> Date: Mon, 14 Feb 2022 23:15:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=20ajax=20=E5=AF=B9=20?= =?UTF-8?q?form=20=E6=A0=BC=E5=BC=8F=E7=9A=84=E5=A4=84=E7=90=86=EF=BC=9B?= =?UTF-8?q?=E4=BC=98=E5=8C=96=20Debugger=EF=BC=9B=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + package.json | 45 ++++++++++++++++++++++--------------------- src/push/push-plus.ts | 2 +- src/utils/ajax.ts | 24 +++++++---------------- 4 files changed, 32 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index b0efed3..6a64fc2 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ License: MIT

+ > Push All In One!支持 Server酱、酷推、邮件、钉钉机器人、企业微信机器人、企业微信应用、pushplus、iGot 等多种推送方式。 > > 温馨提示:出于安全考虑,**所有**推送方式请在**服务端**使用!请勿在**客户端**使用! diff --git a/package.json b/package.json index 14304af..9a9e574 100644 --- a/package.json +++ b/package.json @@ -46,57 +46,58 @@ "prepare": "husky install" }, "devDependencies": { - "@commitlint/cli": "^16.1.0", - "@commitlint/config-conventional": "^16.0.0", - "@microsoft/api-extractor": "^7.13.1", - "@rollup/plugin-alias": "^3.1.2", + "@commitlint/cli": "16.2.1", + "@commitlint/config-conventional": "16.2.1", + "@microsoft/api-extractor": "7.19.4", + "@rollup/plugin-alias": "3.1.9", "@rollup/plugin-commonjs": "^21.0.1", "@rollup/plugin-json": "^4.1.0", - "@rollup/plugin-node-resolve": "^13.0.0", - "@rollup/plugin-replace": "^3.0.0", + "@rollup/plugin-node-resolve": "13.1.3", + "@rollup/plugin-replace": "3.1.0", "@rollup/plugin-typescript": "^8.2.0", "@semantic-release/changelog": "^6.0.1", "@semantic-release/git": "^10.0.1", - "@types/crypto-js": "^4.0.1", + "@types/crypto-js": "4.1.0", "@types/debug": "^4.1.5", "@types/lodash": "^4.14.168", "@types/mocha": "^9.0.0", "@types/module-alias": "^2.0.0", - "@types/node": "^17.0.2", + "@types/node": "17.0.17", "@types/qs": "^6.9.5", - "@typescript-eslint/eslint-plugin": "^5.10.0", - "@typescript-eslint/parser": "^5.10.0", + "@typescript-eslint/eslint-plugin": "5.11.0", + "@typescript-eslint/parser": "5.11.0", "commitizen": "^4.2.3", - "conventional-changelog-cli": "^2.1.1", - "conventional-changelog-cmyr-config": "^2.0.3", + "conventional-changelog-cli": "2.2.2", + "conventional-changelog-cmyr-config": "2.0.4", "cross-env": "^7.0.3", "cz-conventional-changelog": "^3.3.0", "cz-conventional-changelog-cmyr": "^1.0.0", - "eslint": "^8.7.0", - "eslint-config-cmyr": "^1.1.15", - "eslint-plugin-import": "^2.22.1", + "eslint": "8.9.0", + "eslint-config-cmyr": "1.1.17", + "eslint-plugin-import": "2.25.4", "husky": "^7.0.1", - "lint-staged": "^12.1.3", + "lint-staged": "12.3.4", "lodash": "^4.17.21", - "mocha": "^9.0.0", + "mocha": "9.2.0", "module-alias": "^2.2.2", "rimraf": "^3.0.2", - "rollup": "^2.39.1", + "rollup": "2.67.2", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-terser": "^7.0.2", "semantic-release": "^19.0.2", "should": "^13.2.3", - "ts-node": "^10.0.0", + "ts-node": "10.5.0", "ts-node-dev": "^1.1.6", - "typescript": "^4.2.2", + "tslib": "^2.3.1", + "typescript": "4.5.5", "validate-commit-msg": "^2.14.0" }, "dependencies": { - "axios": "^0.25.0", + "axios": "0.26.0", "colors": "^1.4.0", "crypto-js": "^4.0.0", "debug": "^4.3.1", - "qs": "^6.9.6" + "qs": "6.10.3" }, "config": { "commitizen": { diff --git a/src/push/push-plus.ts b/src/push/push-plus.ts index ac7a798..f058950 100644 --- a/src/push/push-plus.ts +++ b/src/push/push-plus.ts @@ -50,7 +50,7 @@ export class PushPlus implements Send { * @returns */ send(title: string, content?: string, template: TemplateType = 'html', channel: ChannelType = 'wechat'): Promise> { - Debugger('title: "%s", content: "%s", template: "%s"', title, content, template) + Debugger('title: "%s", content: "%s", template: "%s", channel: "%s"', title, content, template, channel) return ajax({ url: 'http://www.pushplus.plus/send', method: 'POST', diff --git a/src/utils/ajax.ts b/src/utils/ajax.ts index 6327d59..7d7b0f0 100644 --- a/src/utils/ajax.ts +++ b/src/utils/ajax.ts @@ -24,29 +24,19 @@ interface AjaxConfig { export async function ajax(config: AjaxConfig): Promise> { try { Debugger('ajax config: %O', config) - const { url, query = {}, data = {}, method = 'GET', headers = {} } = config + const { url, query = {}, method = 'GET', headers = {} } = config + let { data = {} } = config + + if (headers['Content-Type'] === 'application/x-www-form-urlencoded' && typeof data === 'object') { + data = qs.stringify(data) + } + const response = await axios(url, { method, headers, params: query, data, timeout: 10000, - transformRequest(reqData: any, reqHeaders?: Record) { - const contentType = Object.keys(reqHeaders).find((e) => e.toLocaleLowerCase().includes('Content-Type'.toLocaleLowerCase())) - if (reqHeaders[contentType] === 'application/x-www-form-urlencoded' && typeof reqData === 'object') { - return qs.stringify(reqData) - } - if (typeof reqData === 'string') { - return reqData - } - if (reqData instanceof Buffer || reqData instanceof ArrayBuffer) { - return reqData - } - if (!reqHeaders['Content-Type']) { - reqHeaders['Content-Type'] = 'application/json' - } - return JSON.stringify(reqData) - }, }) Debugger('response data: %O', response.data) return response