-
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.
新增PushBullet, SimplePush, AnPush推送平台
- Loading branch information
Showing
17 changed files
with
1,120 additions
and
5 deletions.
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
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,95 @@ | ||
'use strict'; | ||
|
||
var _defineProperty = require("@babel/runtime/helpers/defineProperty"); | ||
var axios = require('axios'); | ||
var tool = require('./tool'); | ||
class AnPush { | ||
constructor({ | ||
token, | ||
key, | ||
channel, | ||
proxy | ||
}) { | ||
_defineProperty(this, "_KEY", void 0); | ||
_defineProperty(this, "baseURL", 'https://api.anpush.com/push/'); | ||
_defineProperty(this, "httpsAgent", void 0); | ||
_defineProperty(this, "channel", void 0); | ||
const $key = { | ||
token, | ||
channel, | ||
...key | ||
}; | ||
if (!$key.token) { | ||
throw new Error('Missing Parameter: token'); | ||
} | ||
if ($key.channel) { | ||
this.channel = $key.channel; | ||
} | ||
this._KEY = $key.token; | ||
if (proxy && proxy.enable) { | ||
this.httpsAgent = tool.proxy2httpsAgent(proxy); | ||
} | ||
} | ||
async send(sendOptions) { | ||
if (!sendOptions.message && !sendOptions.customOptions) { | ||
return { | ||
status: 0, | ||
statusText: 'Missing Parameter: message', | ||
extraMessage: null | ||
}; | ||
} | ||
let anPushOptions; | ||
if (sendOptions.customOptions) { | ||
anPushOptions = sendOptions.customOptions; | ||
} else { | ||
anPushOptions = { | ||
channel: this.channel, | ||
content: sendOptions.message, | ||
title: sendOptions.title || sendOptions.message.split('\n')[0].trim().slice(0, 10) | ||
}; | ||
} | ||
if (sendOptions.extraOptions) { | ||
anPushOptions = { | ||
...anPushOptions, | ||
...sendOptions.extraOptions | ||
}; | ||
} | ||
const axiosOptions = { | ||
url: `${this.baseURL}${this._KEY}`, | ||
method: 'POST', | ||
headers: { | ||
'Content-type': 'application/x-www-form-urlencoded' | ||
}, | ||
data: anPushOptions | ||
}; | ||
if (this.httpsAgent) { | ||
axiosOptions.httpsAgent = this.httpsAgent; | ||
} | ||
return axios(axiosOptions).then(response => { | ||
if (response.data) { | ||
if (response.data.code === 200) { | ||
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.AnPush = AnPush; |
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,90 @@ | ||
'use strict'; | ||
|
||
var _defineProperty = require("@babel/runtime/helpers/defineProperty"); | ||
var axios = require('axios'); | ||
var tool = require('./tool'); | ||
class PushBullet { | ||
constructor({ | ||
token, | ||
key, | ||
proxy | ||
}) { | ||
_defineProperty(this, "_KEY", void 0); | ||
_defineProperty(this, "baseURL", 'https://api.pushbullet.com/v2/pushes'); | ||
_defineProperty(this, "httpsAgent", void 0); | ||
const $key = { | ||
token, | ||
...key | ||
}; | ||
if (!$key.token) { | ||
throw new Error('Missing Parameter: token'); | ||
} | ||
this._KEY = $key.token; | ||
if (proxy && proxy.enable) { | ||
this.httpsAgent = tool.proxy2httpsAgent(proxy); | ||
} | ||
} | ||
async send(sendOptions) { | ||
if (!sendOptions.message && !sendOptions.customOptions) { | ||
return { | ||
status: 0, | ||
statusText: 'Missing Parameter: message', | ||
extraMessage: null | ||
}; | ||
} | ||
let pushBulletOptions; | ||
if (sendOptions.customOptions) { | ||
pushBulletOptions = sendOptions.customOptions; | ||
} else { | ||
pushBulletOptions = { | ||
type: 'note', | ||
body: sendOptions.message, | ||
title: sendOptions.title || sendOptions.message.split('\n')[0].trim().slice(0, 10) | ||
}; | ||
} | ||
if (sendOptions.extraOptions) { | ||
pushBulletOptions = { | ||
...pushBulletOptions, | ||
...sendOptions.extraOptions | ||
}; | ||
} | ||
const axiosOptions = { | ||
url: this.baseURL, | ||
method: 'POST', | ||
headers: { | ||
'Access-Token': this._KEY, | ||
'Content-type': 'application/json' | ||
}, | ||
data: pushBulletOptions | ||
}; | ||
if (this.httpsAgent) { | ||
axiosOptions.httpsAgent = this.httpsAgent; | ||
} | ||
return axios(axiosOptions).then(response => { | ||
if (response.data) { | ||
if (response.status === 200) { | ||
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.PushBullet = PushBullet; |
Oops, something went wrong.