|
|
function checkKey(apikey) { |
|
|
const fs = require('fs'); |
|
|
|
|
|
var pa = "/data_apikey.json" |
|
|
try { |
|
|
if(!apikey) return { |
|
|
error: 1, |
|
|
msg: 'thiếu api key' |
|
|
} |
|
|
const data_apikey = require("./data_apikey.json"); |
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
module.exports = { |
|
|
checkKey |
|
|
}; |
|
|
|
|
|
|