Skip to content

Commit

Permalink
fix: 优化 ajax 对 form 格式的处理;优化 Debugger;更新依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoMeiYouRen committed Feb 14, 2022
1 parent d36e44d commit 5326c62
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 40 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
</a>
</p>

> Push All In One!支持 Server酱、酷推、邮件、钉钉机器人、企业微信机器人、企业微信应用、pushplus、iGot 等多种推送方式。
>
> 温馨提示:出于安全考虑,**所有**推送方式请在**服务端**使用!请勿在**客户端**使用!
Expand Down
45 changes: 23 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/push/push-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class PushPlus implements Send {
* @returns
*/
send(title: string, content?: string, template: TemplateType = 'html', channel: ChannelType = 'wechat'): Promise<AxiosResponse<any>> {
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',
Expand Down
24 changes: 7 additions & 17 deletions src/utils/ajax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,19 @@ interface AjaxConfig {
export async function ajax(config: AjaxConfig): Promise<AxiosResponse<any>> {
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<string, unknown>) {
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
Expand Down

0 comments on commit 5326c62

Please sign in to comment.