Initial commit

This commit is contained in:
Ilya 2021-12-19 19:49:22 +03:00
commit 42cec0a8f2
5 changed files with 66 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
node_modules
test
package-lock.json
.idea

4
.npmignore Normal file
View file

@ -0,0 +1,4 @@
.idea
.git
node_modules
test

16
package.json Normal file
View 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
View 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
View 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();
}
}