mirror of
https://github.com/glenndehaan/unifi-voucher-site.git
synced 2026-04-05 08:54:17 -04:00
Updated dependencies. Also changed the way a controller object is created
This commit is contained in:
@@ -16,13 +16,6 @@ const config = {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create new UniFi controller object
|
||||
*
|
||||
* @type {Controller}
|
||||
*/
|
||||
const controller = new unifi.Controller({host: config.unifi.ip, port: config.unifi.port, site: config.unifi.siteID, sslverify: false});
|
||||
|
||||
/**
|
||||
* Exports the UniFi voucher function
|
||||
*
|
||||
@@ -31,6 +24,16 @@ const controller = new unifi.Controller({host: config.unifi.ip, port: config.uni
|
||||
*/
|
||||
module.exports = (type) => {
|
||||
return new Promise((resolve) => {
|
||||
/**
|
||||
* Create new UniFi controller object
|
||||
*
|
||||
* @type {Controller}
|
||||
*/
|
||||
const controller = new unifi.Controller({host: config.unifi.ip, port: config.unifi.port, site: config.unifi.siteID, sslverify: false});
|
||||
|
||||
/**
|
||||
* Login and create a voucher
|
||||
*/
|
||||
controller.login(config.unifi.username, config.unifi.password).then(() => {
|
||||
controller.getSitesStats().then(() => {
|
||||
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) => {
|
||||
@@ -38,18 +41,22 @@ module.exports = (type) => {
|
||||
const voucher = `${[voucher_data_complete[0].code.slice(0, 5), '-', voucher_data_complete[0].code.slice(5)].join('')}`;
|
||||
resolve(voucher);
|
||||
}).catch((e) => {
|
||||
console.log('Error while getting voucher!');
|
||||
console.log(e);
|
||||
process.exit(1);
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.log('Error while creating voucher!');
|
||||
console.log(e);
|
||||
process.exit(1);
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.log('Error while getting site stats!');
|
||||
console.log(e);
|
||||
process.exit(1);
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.log('Error while logging in!');
|
||||
console.log(e);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user