diff --git a/index.js b/index.js new file mode 100644 index 0000000..080610a --- /dev/null +++ b/index.js @@ -0,0 +1,56 @@ +const https = require("http") + +module.exports = class userdb{ + #token // Private Field + constructor(token){ + if(token && token.trim() != ""){ + if(token.match(/([A-F0-9a-f]){64}/g)){ + // console.log(`Token set as ${token}`); + this.#token = token + }else{ + console.log("Error: token does not follow the correct format\nMake sure that you copied the token correctly"); + } + }else{ + return false + } + } + + fetch (userid) { + return new Promise(async resolve => { + if(!this.#token) + resolve("You need to specify your token in the constructor") + if(userid == undefined || userid.length < 18 || userid.length > 20){ + resolve("You need to supply a valid user id") + } + const options = { + hostname: 'watchfox.kitsunes.eu', + port:2544, + path: `/dataHandling?function=get_score&token=${this.#token}&userid=${userid}`, + method: 'GET' + } + // const options = { + // hostname: 'localhost', + // port: 2544, + // path: `/dataHandling?function=get_score&token=${this.#token}&userid=${userid}`, + // method: 'GET' + // } + + const req = https.request(options, res => { + var data = "" + res.on('data', chunk => { + data += chunk; + }); + res.on('end', () => { + data = JSON.parse(data); + resolve(data) + }) + }) + req.on('error', error => { + console.error(error) + resolve(error) + }) + req.end() + }) + } +} + diff --git a/package.json b/package.json new file mode 100644 index 0000000..224b1e4 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "watchfox", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "4n0nh4x0r", + "license": "MIT", + "homepage": "https://github.com/owner/project#readme", + "repository": { + "type": "git", + "url": "https://github.com/npm/cli.git" + } +}