mirror of
https://github.com/glenndehaan/unifi-voucher-site.git
synced 2026-03-31 06:24:02 -04:00
Implemented remapping of expiration
This commit is contained in:
20
server.js
20
server.js
@@ -11,6 +11,7 @@ const app = express();
|
||||
*/
|
||||
const logo = require('./modules/logo');
|
||||
const types = require('./modules/types');
|
||||
const time = require('./modules/time');
|
||||
const unifi = require('./modules/unifi');
|
||||
|
||||
/**
|
||||
@@ -29,7 +30,7 @@ logo();
|
||||
*/
|
||||
console.log('[VoucherType] Loaded the following types:');
|
||||
voucherTypes.forEach((type, key) => {
|
||||
console.log(`[VoucherType][${key}] ${type.expiration} minutes, ${type.usage === '1' ? 'single-use' : 'multi-use'}${typeof type.upload === "undefined" && typeof type.download === "undefined" && typeof type.megabytes === "undefined" ? ', no limits' : `${typeof type.upload !== "undefined" ? `, upload bandwidth limit: ${type.upload} kb/s` : ''}${typeof type.download !== "undefined" ? `, download bandwidth limit: ${type.download} kb/s` : ''}${typeof type.megabytes !== "undefined" ? `, quota limit: ${type.megabytes} mb` : ''}`}`);
|
||||
console.log(`[VoucherType][${key}] ${time(type.expiration)}, ${type.usage === '1' ? 'single-use' : 'multi-use'}${typeof type.upload === "undefined" && typeof type.download === "undefined" && typeof type.megabytes === "undefined" ? ', no limits' : `${typeof type.upload !== "undefined" ? `, upload bandwidth limit: ${type.upload} kb/s` : ''}${typeof type.download !== "undefined" ? `, download bandwidth limit: ${type.download} kb/s` : ''}${typeof type.megabytes !== "undefined" ? `, quota limit: ${type.megabytes} mb` : ''}`}`);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -79,6 +80,7 @@ app.get('/', (req, res) => {
|
||||
banner_image: process.env.BANNER_IMAGE || `/images/bg-${random(1, 10)}.jpg`,
|
||||
app_header: timeHeader,
|
||||
sid: uuidv4(),
|
||||
timeConvert: time,
|
||||
voucher_types: voucherTypes
|
||||
});
|
||||
});
|
||||
@@ -88,13 +90,20 @@ app.post('/', async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const check = req.body.password === (process.env.SECURITY_CODE || "0000");
|
||||
const passwordCheck = req.body.password === (process.env.SECURITY_CODE || "0000");
|
||||
|
||||
if(!check) {
|
||||
if(!passwordCheck) {
|
||||
res.redirect(encodeURI(`/?error=Invalid password!`));
|
||||
return;
|
||||
}
|
||||
|
||||
const typeCheck = (process.env.VOUCHER_TYPES || '480,0,,,;').split(';').includes(req.body['voucher-type']);
|
||||
|
||||
if(!typeCheck) {
|
||||
res.redirect(encodeURI(`/?error=Unknown type!`));
|
||||
return;
|
||||
}
|
||||
|
||||
res.redirect(encodeURI(`/voucher?code=${req.body.password}&type=${req.body['voucher-type']}`));
|
||||
});
|
||||
app.get('/voucher', async (req, res) => {
|
||||
@@ -103,6 +112,11 @@ app.get('/voucher', async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!(process.env.VOUCHER_TYPES || '480,0,,,;').split(';').includes(req.query.type)) {
|
||||
res.status(400).send();
|
||||
return;
|
||||
}
|
||||
|
||||
const hour = new Date().getHours();
|
||||
const timeHeader = hour < 12 ? 'Good Morning' : hour < 18 ? 'Good Afternoon' : 'Good Evening';
|
||||
const voucherCode = await unifi(types(req.query.type, true));
|
||||
|
||||
Reference in New Issue
Block a user