Implemented voucher types. Updated the README.md

This commit is contained in:
Glenn de Haan
2022-11-14 16:36:29 +01:00
parent 006343a248
commit 65c29e2e83
8 changed files with 120 additions and 15 deletions

View File

@@ -26,13 +26,14 @@ const controller = new unifi.Controller({host: config.unifi.ip, port: config.uni
/**
* Exports the UniFi voucher function
*
* @param type
* @returns {Promise<unknown>}
*/
module.exports = () => {
module.exports = (type) => {
return new Promise((resolve) => {
controller.login(config.unifi.username, config.unifi.password).then(() => {
controller.getSitesStats().then(() => {
controller.createVouchers(480).then((voucher_data) => {
controller.createVouchers(type.expiration, 1, type.usage === 1 ? 1 : 0, null, typeof type.upload !== "undefined" ? type.upload : null, typeof type.download !== "undefined" ? type.download : null, typeof type.megabytes !== "undefined" ? type.megabytes : null).then((voucher_data) => {
controller.getVouchers(voucher_data[0].create_time).then((voucher_data_complete) => {
const voucher = `${[voucher_data_complete[0].code.slice(0, 5), '-', voucher_data_complete[0].code.slice(5)].join('')}`;
resolve(voucher);