function checkKey(apikey) { const fs = require('fs'); //console.log("hell") var pa = "/data_apikey.json" try { if(!apikey) return { error: 1, msg: 'thiếu api key' } const data_apikey = require("./data_apikey.json");//global.APIKEY if (!data_apikey.find(i => i.apikey == apikey)) { return { error: 1, msg: 'APIKEY KHÔNG CHÍNH XÁC!' } } else { let APIKEY = data_apikey.find(i => i.apikey == apikey); if (APIKEY.request == 0) { return { error: 1, msg: 'APIKEY của bạn đã hết lượt request' } } else { if (APIKEY.type == 'free') { APIKEY.request = APIKEY.request - 1; fs.writeFileSync(__dirname+"/data_apikey.json", JSON.stringify(data_apikey, null, 4)); return { error: 0 } } if (APIKEY.type == 'premium') { return { error: 0 } } } } } catch (e) { return console.log(e)/*{ error: 1, msg: 'Đã xảy ra lỗi với API KEY của bạn!' }*/ } } module.exports = { checkKey };