-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
482 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
'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 IGot { | ||
constructor({ | ||
token, | ||
key, | ||
proxy | ||
}) { | ||
_defineProperty(this, "_KEY", void 0); | ||
|
||
_defineProperty(this, "baseURL", 'https://push.hellyw.com/'); | ||
|
||
_defineProperty(this, "httpsAgent", void 0); | ||
|
||
if (!token && !(key !== null && key !== void 0 && key.token)) { | ||
throw new Error('Missing Parameter: token'); | ||
} // @ts-ignore | ||
|
||
|
||
this._KEY = token || key.token; | ||
|
||
if (proxy) { | ||
this.httpsAgent = tool.proxy2httpsAgent(proxy); | ||
} | ||
} | ||
|
||
async send(sendOptions) { | ||
if (!sendOptions.message && !sendOptions.customOptions) { | ||
return { | ||
status: 0, | ||
statusText: 'Missing Parameter: message', | ||
extraMessage: null | ||
}; | ||
} | ||
|
||
let iGotOptions; | ||
|
||
if (sendOptions.customOptions) { | ||
iGotOptions = sendOptions.customOptions; | ||
} else { | ||
iGotOptions = { | ||
title: sendOptions.title || sendOptions.message.split('\n')[0].trim().slice(0, 10), | ||
content: sendOptions.message | ||
}; | ||
} | ||
|
||
if (sendOptions.extraOptions) { | ||
iGotOptions = { ...iGotOptions, | ||
...sendOptions.extraOptions | ||
}; | ||
} | ||
|
||
const axiosOptions = { | ||
url: `${this.baseURL}${this._KEY}`, | ||
method: 'POST', | ||
headers: { | ||
'Content-type': 'application/json' | ||
}, | ||
data: iGotOptions | ||
}; | ||
|
||
if (this.httpsAgent) { | ||
axiosOptions.httpsAgent = this.httpsAgent; | ||
} | ||
|
||
return axios__default["default"](axiosOptions).then(response => { | ||
if (response.data) { | ||
if (response.data.ret === 0) { | ||
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.IGot = IGot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
'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 NowPush { | ||
constructor({ | ||
token, | ||
key, | ||
proxy | ||
}) { | ||
_defineProperty(this, "_KEY", void 0); | ||
|
||
_defineProperty(this, "baseURL", 'https://www.api.nowpush.app/v3/sendMessage'); | ||
|
||
_defineProperty(this, "httpsAgent", void 0); | ||
|
||
if (!token && !(key !== null && key !== void 0 && key.token)) { | ||
throw new Error('Missing Parameter: token'); | ||
} // @ts-ignore | ||
|
||
|
||
this._KEY = token || key.token; | ||
|
||
if (proxy) { | ||
this.httpsAgent = tool.proxy2httpsAgent(proxy); | ||
} | ||
} | ||
|
||
async send(sendOptions) { | ||
if (!sendOptions.message && !sendOptions.customOptions) { | ||
return { | ||
status: 0, | ||
statusText: 'Missing Parameter: message', | ||
extraMessage: null | ||
}; | ||
} | ||
|
||
let nowPushOptions; | ||
|
||
if (sendOptions.customOptions) { | ||
nowPushOptions = sendOptions.customOptions; | ||
} else { | ||
nowPushOptions = { | ||
message_type: 'nowpush_note', | ||
note: sendOptions.message | ||
}; | ||
} | ||
|
||
nowPushOptions.device_type = 'api'; | ||
|
||
if (sendOptions.extraOptions) { | ||
nowPushOptions = { ...nowPushOptions, | ||
...sendOptions.extraOptions | ||
}; | ||
} | ||
|
||
const axiosOptions = { | ||
url: this.baseURL, | ||
method: 'POST', | ||
headers: { | ||
'Content-type': 'application/x-www-form-urlencoded', | ||
Authorization: `Bearer ${this._KEY}` | ||
}, | ||
data: tool.queryStringify(nowPushOptions) | ||
}; | ||
|
||
if (this.httpsAgent) { | ||
axiosOptions.httpsAgent = this.httpsAgent; | ||
} | ||
|
||
return axios__default["default"](axiosOptions).then(response => { | ||
if (response.data) { | ||
if (response.data.isError === false) { | ||
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.NowPush = NowPush; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { AxiosRequestConfig } from 'axios'; | ||
import { proxy, result, sendOptions } from './tool'; | ||
interface IGotConfig { | ||
key?: { | ||
token: string; | ||
}; | ||
token?: string; | ||
proxy?: proxy; | ||
} | ||
declare class IGot { | ||
protected _KEY: string; | ||
readonly baseURL = "https://push.hellyw.com/"; | ||
httpsAgent?: AxiosRequestConfig['httpsAgent']; | ||
constructor({ token, key, proxy }: IGotConfig); | ||
send(sendOptions: sendOptions): Promise<result>; | ||
} | ||
export { IGot }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { AxiosRequestConfig } from 'axios'; | ||
import { proxy, result, sendOptions } from './tool'; | ||
interface NowPushConfig { | ||
key?: { | ||
token: string; | ||
}; | ||
token?: string; | ||
proxy?: proxy; | ||
} | ||
declare class NowPush { | ||
protected _KEY: string; | ||
readonly baseURL = "https://www.api.nowpush.app/v3/sendMessage"; | ||
httpsAgent?: AxiosRequestConfig['httpsAgent']; | ||
constructor({ token, key, proxy }: NowPushConfig); | ||
send(sendOptions: sendOptions): Promise<result>; | ||
} | ||
export { NowPush }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.