Skip to content

Commit

Permalink
更换打包方式
Browse files Browse the repository at this point in the history
  • Loading branch information
HCLonely committed May 9, 2022
1 parent 5698867 commit fd6bcf1
Show file tree
Hide file tree
Showing 149 changed files with 10,389 additions and 4,712 deletions.
15 changes: 10 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"extends": [
"eslint:recommended"
],
"ignorePatterns": [
"dist/**/*"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
Expand All @@ -14,8 +17,7 @@
"plugins": [
"@typescript-eslint"
],
"globals": {
},
"globals": {},
"rules": {
"indent": [
"error",
Expand Down Expand Up @@ -150,9 +152,12 @@
"error",
"always"
],
"newline-per-chained-call": [2, {
"ignoreChainWithDepth": 3
}],
"newline-per-chained-call": [
2,
{
"ignoreChainWithDepth": 3
}
],
"no-whitespace-before-property": "error",
"padded-blocks": [
"error",
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# all-pusher-api

## ToDo

types

统一化推送服务Nodejs API. 已支持钉钉, Discord, 邮件, 飞书, PushDeer, PushPlus, QQ, QQ 频道机器人, Server 酱, Showdoc Push, Telegram Bot, 企业微信群机器人, 息知, WxPusher等平台.

**!!!!!仅推送!!!!!不交互!!!!!!**
Expand Down
253 changes: 146 additions & 107 deletions dist/Custom.js
Original file line number Diff line number Diff line change
@@ -1,112 +1,151 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Custom = void 0;
/* global result, CustomConfig */
const axios_1 = __importDefault(require("axios"));
const tool_1 = require("./tool");
'use strict';

var _defineProperty = require("@babel/runtime/helpers/defineProperty");

Object.defineProperty(exports, '__esModule', {
value: true
});

var axios = require('axios');

var tool = require('./tool');

function _interopDefaultLegacy(e) {
return e && typeof e === 'object' && 'default' in e ? e : {
'default': e
};
}

var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);

class Custom {
constructor({ url, method, contentType, headers, key, success, proxy }) {
this.method = 'POST';
this.contentType = 'application/json';
if (!url && !(key === null || key === void 0 ? void 0 : key.url)) {
throw new Error('Missing Parameter: url');
}
if (!success && !(key === null || key === void 0 ? void 0 : key.success)) {
throw new Error('Missing Parameter: success');
}
// @ts-ignore
this._URL = url || key.url;
// @ts-ignore
this.success = success || key.success;
if (method || (key === null || key === void 0 ? void 0 : key.method)) {
// @ts-ignore
this.method = method || key.method;
}
if (contentType || (key === null || key === void 0 ? void 0 : key.contentType)) {
// @ts-ignore
this.contentType = contentType || key.contentType;
}
if (headers || (key === null || key === void 0 ? void 0 : key.headers)) {
// @ts-ignore
this._HEADERS = headers || key.headers;
}
if (proxy) {
this.httpsAgent = (0, tool_1.proxy2httpsAgent)(proxy);
}
constructor({
url,
method,
contentType,
headers,
key,
success,
proxy
}) {
_defineProperty(this, "_URL", void 0);

_defineProperty(this, "httpsAgent", void 0);

_defineProperty(this, "method", 'POST');

_defineProperty(this, "contentType", 'application/json');

_defineProperty(this, "_HEADERS", void 0);

_defineProperty(this, "success", void 0);

if (!url && !(key !== null && key !== void 0 && key.url)) {
throw new Error('Missing Parameter: url');
}
send(sendOptions) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const axiosOptions = {
url: this._URL,
method: this.method,
headers: {
'Content-type': 'application/json'
},
data: sendOptions.extraMessage || sendOptions
};
if (this._HEADERS) {
axiosOptions.headers = this._HEADERS;
}
if (this.contentType) {
axiosOptions.headers['Content-type'] = this.contentType;
}
if (this.httpsAgent) {
axiosOptions.httpsAgent = this.httpsAgent;
}
if (((_a = axiosOptions.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'POST' &&
axiosOptions.headers['Content-type'] === 'application/x-www-form-urlencoded') {
axiosOptions.data = (0, tool_1.queryStringify)(sendOptions);
}
if (((_b = axiosOptions.method) === null || _b === void 0 ? void 0 : _b.toUpperCase()) === 'GET') {
axiosOptions.data = null;
axiosOptions.url += (0, tool_1.queryStringify)(sendOptions);
}
return (0, axios_1.default)(axiosOptions).then((response) => {
if (response.data) {
let variate = response.data;
this.success.key.split('.').forEach((key, index) => {
if (index === 0) {
return;
}
variate = variate === null || variate === void 0 ? void 0 : variate[key];
});
if (variate === this.success.value) {
return {
status: 200,
statusText: 'Success',
extraMessage: response
};
}
return {
status: 100,
statusText: 'Error',
extraMessage: response
};
}
return {
status: 101,
statusText: 'No Response Data',
extraMessage: response
};
}).catch((error) => ({
status: 102,
statusText: 'Request Error',
extraMessage: error
}));
});

if (!success && !(key !== null && key !== void 0 && key.success)) {
throw new Error('Missing Parameter: success');
} // @ts-ignore


this._URL = url || key.url; // @ts-ignore

this.success = success || key.success;

if (method || key !== null && key !== void 0 && key.method) {
// @ts-ignore
this.method = method || key.method;
}

if (contentType || key !== null && key !== void 0 && key.contentType) {
// @ts-ignore
this.contentType = contentType || key.contentType;
}

if (headers || key !== null && key !== void 0 && key.headers) {
// @ts-ignore
this._HEADERS = headers || key.headers;
}

if (proxy) {
this.httpsAgent = tool.proxy2httpsAgent(proxy);
}
}

async send(sendOptions) {
var _axiosOptions$method, _axiosOptions$method2;

const axiosOptions = {
url: this._URL,
method: this.method,
headers: {
'Content-type': 'application/json'
},
data: sendOptions.extraMessage || sendOptions
};

if (this._HEADERS) {
axiosOptions.headers = this._HEADERS;
}

if (this.contentType) {
axiosOptions.headers['Content-type'] = this.contentType;
}

if (this.httpsAgent) {
axiosOptions.httpsAgent = this.httpsAgent;
}

if (((_axiosOptions$method = axiosOptions.method) === null || _axiosOptions$method === void 0 ? void 0 : _axiosOptions$method.toUpperCase()) === 'POST' && axiosOptions.headers['Content-type'] === 'application/x-www-form-urlencoded') {
axiosOptions.data = tool.queryStringify(sendOptions);
}

if (((_axiosOptions$method2 = axiosOptions.method) === null || _axiosOptions$method2 === void 0 ? void 0 : _axiosOptions$method2.toUpperCase()) === 'GET') {
axiosOptions.data = null;
axiosOptions.url += tool.queryStringify(sendOptions);
}

return axios__default["default"](axiosOptions).then(response => {
if (response.data) {
let variate = response.data;
this.success.key.split('.').forEach((key, index) => {
var _variate;

if (index === 0) {
return;
}

variate = (_variate = variate) === null || _variate === void 0 ? void 0 : _variate[key];
});

if (variate === this.success.value) {
return {
status: 200,
statusText: 'Success',
extraMessage: response
};
}

return {
status: 100,
statusText: 'Error',
extraMessage: response
};
}

return {
status: 101,
statusText: 'No Response Data',
extraMessage: response
};
}).catch(error => ({
status: 102,
statusText: 'Request Error',
extraMessage: error
}));
}

}

exports.Custom = Custom;
Loading

0 comments on commit fd6bcf1

Please sign in to comment.