Initial commit
This commit is contained in:
commit
42cec0a8f2
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
node_modules
|
||||
test
|
||||
package-lock.json
|
||||
.idea
|
4
.npmignore
Normal file
4
.npmignore
Normal file
|
@ -0,0 +1,4 @@
|
|||
.idea
|
||||
.git
|
||||
node_modules
|
||||
test
|
16
package.json
Normal file
16
package.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "uptimekuma-api",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "src/index.js",
|
||||
"types": "src/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "node test/test.js"
|
||||
},
|
||||
"keywords": ["uptime","kuma"],
|
||||
"author": "RedGuys",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"axios": "^0.21.1"
|
||||
}
|
||||
}
|
9
src/index.d.ts
vendored
Normal file
9
src/index.d.ts
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
export default class UptimeKumaApi {
|
||||
constructor();
|
||||
|
||||
startPushing(url:string, interval?:number);
|
||||
cancelPushing();
|
||||
|
||||
on(event: "pushSuccessful", handle: (url: string) => void);
|
||||
on(event: "pushFailed", handle: (url: string, err: Error) => void);
|
||||
}
|
33
src/index.js
Normal file
33
src/index.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
const client = require("axios").default;
|
||||
const EventEmitter = require("events");
|
||||
|
||||
module.exports = class UptimeKumaApi extends EventEmitter {
|
||||
|
||||
_pushTimer;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
push(url) {
|
||||
client.get(url).then(res => {
|
||||
this.emit("pushSuccessful", url);
|
||||
}).catch(err => {
|
||||
this.emit("pushFailed", url, err);
|
||||
});
|
||||
}
|
||||
|
||||
startPushing(url, interval=60) {
|
||||
if(this._pushTimer)
|
||||
this._pushTimer.cancel();
|
||||
this._pushTimer = setInterval(() => {
|
||||
this.push(url);
|
||||
}, interval*1000);
|
||||
this.push(url);
|
||||
}
|
||||
|
||||
cancelPushing() {
|
||||
if(this._pushTimer)
|
||||
this._pushTimer.cancel();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue