const axios = require("axios"); class BackendIntegration { url = ""; secret_key = ""; up = false; prices = {}; constructor() { this.url = process.env.BACKEND_URL; this.secret_key = process.env.SECRET_KEY; } async pulse() { return await axios.get(`${this.url}/api/pulse/db`, {headers:{Cookie:`secretkey=${this.secret_key};`}}).then( response => { this.up = response.status === 200; } ).catch((e)=>{console.log("pulse failed!")}) } getPrices(tc) { axios.get(`${this.url}/api/external/vip`, {headers:{Cookie:`secretkey=${this.secret_key};`}}).then( response => { if (response.status === 200) { tc.setPrices(response.data); } else {console.log("cannot get prices"); process.exit(200)} } ).catch(()=>{this.prices = {}; console.log("set prices to null");}); } vip(steam64, amount, extra, uniq) { axios.post(`${this.url}/api/external/vip?steam=${steam64}&amount=${Math.round(amount)}&service=steam&extra=${extra}&unique=${uniq}`, {}, {headers:{Cookie:`secretkey=${this.secret_key};`}}).then( response => { if (response.status === 200) { if (response.data === 0) { console.log(`[S64:${steam64}] VIP as not be added, maybe permition already exists`) return 99; } else if (response.data > 0) { console.log(`[S64:${steam64}] VIP has be added!`); return 100; } else if (response.data < 0) { console.log(`[S64:${steam64}] VIP has be extends!`); return 101; } } else { console.log(`[S64:${steam64}] Cannot add VIP`); } } ).catch((e)=>{console.log("cannot add vip"); console.log(e)}); } } module.exports = BackendIntegration;