1
0
mirror of https://dev.s-ul.net/Galexion/MaiMaiDXNet.git synced 2024-11-28 00:30:49 +01:00
MaiMaiDXNet/routes/index.js

70 lines
2.4 KiB
JavaScript
Raw Normal View History

2023-02-17 00:50:32 +01:00
var express = require('express');
var router = express.Router();
var fetch = require('cross-fetch');
const sqlite3 = require('sqlite3').verbose();
let db = new sqlite3.Database('A:\\db.sqlite');
/* GET home page. */
var title = 'Webapp Mission Test'
router.get('/', function (req, res, next) {
db.all('SELECT * FROM sega_card', (err, rows) => {
if (err) {
console.error(err);
res.render('error', { error: err });
2023-02-17 00:50:32 +01:00
} else {
console.log(rows);
console.log(`There are Currently ${rows.length} Users Registered.`); // this check could probably be changed into an API
var params = {
totalUsers: rows.length
}
res.render('index', { title: title, params: params });
2023-02-17 00:50:32 +01:00
}
});
});
router.get('/user', async function (req, res, next) {
try{
const cookies = req.cookies
console.log(cookies)
if (cookies.aime_card_id === undefined) {
return res.render('index', { title: title });
}
res.render('user', { title: title, userdata: await getUserData(req) });
} catch (err) {
res.render('error', { error: err });
}
});
2023-02-18 11:19:30 +01:00
router.get('/error/test/db', function (req,res,next) {
res.render('error', { error: "Error: SQLITE_BUSY: database is locked"})
})
async function getUserData(req) {
return new Promise((resolve, reject) => {
const cookies = req.cookies
db.all('SELECT * FROM maimai2_user_detail', (err, rows) => {
2023-02-17 00:50:32 +01:00
if (err) {
console.error(err);
// Return a Failed Message.
reject(err)
2023-02-17 00:50:32 +01:00
} else {
// Make the Request easier to get to.
var mUser = undefined // Leave the Matched User undefined until the user is found.
for (user of rows) { // For Each User in Rows
if (cookies.aime_card_id === user.aime_card_id.toString()) { // If the Access Code for the card is in the system,
mUser = user; // set the Matched User Variable to the User, and break the for Loop.
break;
}
}
if (mUser) {
// Return a Response with the whole identifiable user data. the EXT_ID will be used later to identify images and other things and match them to the user's profile.
resolve(mUser);
} else {
reject(new Error('User not found'));
}
2023-02-17 00:50:32 +01:00
}
});
});
} // function is required to obtain the User Data, and create the user profile. I'm going to bed.
2023-02-17 00:50:32 +01:00
module.exports = router;