mirror of
https://dev.s-ul.net/Galexion/MaiMaiDXNet.git
synced 2024-11-24 04:50:13 +01:00
moved sqlite functions to dbhandler.js in preparation for artemis support
This commit is contained in:
parent
70812e0da2
commit
46bd7af3e1
190
dbhandler.js
Normal file
190
dbhandler.js
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
const { serverType, ArtConnSettings,DXMemorialImageDirectory } = require('./config.json');
|
||||||
|
const sqlite3 = require('sqlite3').verbose();
|
||||||
|
let db = new sqlite3.Database(DXMemorialImageDirectory + '\\db.sqlite');
|
||||||
|
|
||||||
|
// index.js route '/'
|
||||||
|
async function getUserCount() {
|
||||||
|
if (serverType === 0) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
db.all('SELECT * FROM sega_card', (err, rows) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
res.render('error', { error: err });
|
||||||
|
reject(err)
|
||||||
|
} else {
|
||||||
|
resolve(rows.length)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// index.js & api.js /getUserData/
|
||||||
|
async function getUserData(req) {
|
||||||
|
if (serverType === 0) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const cookies = req.cookies
|
||||||
|
db.all('SELECT * FROM maimai2_user_detail', (err, rows) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
// Return a Failed Message.
|
||||||
|
reject(err)
|
||||||
|
} 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'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}); // function is required to obtain the User Data, and create the user profile. I'm going to bed.
|
||||||
|
} else { // 07-23 oh god im going to have to recreate this function again aren't i
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// api.js /getExtId/
|
||||||
|
async function getExtId(req) {
|
||||||
|
if (serverType === 0) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
db.all('SELECT * FROM sega_card', (err, rows) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
// Return a Failed Message.
|
||||||
|
reject(err)
|
||||||
|
} else {
|
||||||
|
// Make the Request easier to get to.
|
||||||
|
var request = req.body;
|
||||||
|
var mUser = undefined // Leave the Matched User undefined until the user is found.
|
||||||
|
for (user of rows) { // For Each User in Rows
|
||||||
|
if (request.input === user.luid) { // 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 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 {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// api /getUserScores/
|
||||||
|
async function getUserScores(req) {
|
||||||
|
if (serverType === 0) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
db.all('SELECT * FROM maimai2_user_playlog', (err, rows) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
reject(err)
|
||||||
|
// Return a Failed Message.
|
||||||
|
} else {
|
||||||
|
// Make the Request easier to get to.
|
||||||
|
var request = req.body;
|
||||||
|
var mUser = new Array(); // Leave the Matched User's Scores undefined until the user is found.
|
||||||
|
for (score of rows) { // For Each Score in Rows
|
||||||
|
if (request.input == score.user_id) { // If the inputed User ID and Score's User ID Matches,
|
||||||
|
mUser.push(score) // add that score into the array.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Return a Response with all the Scores listed under that user.
|
||||||
|
resolve(mUser)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// api /getUserArea/
|
||||||
|
async function getUserArea(req) {
|
||||||
|
if (serverType === 0) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
db.all('SELECT * FROM maimai2_user_map', (err, rows) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
// Return a Failed Message.
|
||||||
|
reject(err)
|
||||||
|
} else {
|
||||||
|
// Make the Request easier to get to.
|
||||||
|
var request = req.body;
|
||||||
|
var mUser = new Array(); // Leave the Matched User's Areas undefined until the user is found.
|
||||||
|
for (map of rows) { // For Each Area in Rows
|
||||||
|
if (request.input == map.user_id) { // If the inputed User ID and Score's User ID Matches,
|
||||||
|
mUser.push(map) // add that Area into the array.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Return a Response with all the Areas listed under that user.
|
||||||
|
resolve(mUser)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* side note: User Banned & User Unbanned should be tied into 1 commnand that toggles it but maybe not, i dont really know */
|
||||||
|
|
||||||
|
// api /getUserBanned/
|
||||||
|
async function getUserBanned(req) {
|
||||||
|
if (serverType === 0) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
var request = req.body;
|
||||||
|
if (request.input === undefined) {
|
||||||
|
return reject('Failed to update user ban state, insufficent paramaters')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
db.run('UPDATE maimai2_user_detail SET ban_state = ? WHERE id = ?', [2, request.input], function (err) {
|
||||||
|
if (err) {
|
||||||
|
console.error(err.message);
|
||||||
|
reject({"status":"failure","message":"Unable to ban user, see reason","reason":err});
|
||||||
|
} else {
|
||||||
|
resolve({ "status": "Success", "message": `User ${request.input} banned.` })
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// api /getUserUnbanned/
|
||||||
|
async function getUserUnbanned(req) {
|
||||||
|
if (serverType === 0) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
var request = req.body;
|
||||||
|
if (request.input === undefined) {
|
||||||
|
return reject('Failed to update user ban state, insufficent paramaters')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
db.run('UPDATE maimai2_user_detail SET ban_state = ? WHERE id = ?', [0, request.input], function (err) {
|
||||||
|
if (err) {
|
||||||
|
console.error(err.message);
|
||||||
|
reject({"status":"failure","message":"Unable to ban user, see reason","reason":err});
|
||||||
|
} else {
|
||||||
|
resolve({ "status": "Success", "message": `User ${request.input} banned.` })
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {getUserCount,getUserData,getUserScores,getUserArea,getUserBanned,getUserUnbanned,getExtId};
|
60
index.js
60
index.js
@ -9,40 +9,40 @@ var indexRouter = require('./routes/index');
|
|||||||
var apiRouter = require('./routes/api');
|
var apiRouter = require('./routes/api');
|
||||||
var config = require("./config.json");
|
var config = require("./config.json");
|
||||||
|
|
||||||
const watcher = chokidar.watch(config.DXMemorialImageDirectory, {
|
if (config.serverType === 0) { // Only run the image Importer when Aqua is active
|
||||||
|
const watcher = chokidar.watch(config.DXMemorialImageDirectory, {
|
||||||
persistent: true
|
persistent: true
|
||||||
});
|
});
|
||||||
|
|
||||||
watcher
|
watcher
|
||||||
.on('add', (filePath) => {
|
.on('add', (filePath) => {
|
||||||
const isImage = /\.(jpe?g|png|gif)$/i.test(filePath);
|
const isImage = /\.(jpe?g|png|gif)$/i.test(filePath);
|
||||||
if (isImage) {
|
if (isImage) {
|
||||||
const fileName = path.basename(filePath);
|
const fileName = path.basename(filePath);
|
||||||
const destPath = path.join(config.imageFolder, fileName);
|
const destPath = path.join(config.imageFolder, fileName);
|
||||||
fs.access(destPath, (err) => {
|
fs.access(destPath, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
fs.copyFile(filePath, destPath, (err) => {
|
fs.copyFile(filePath, destPath, (err) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log(`${fileName} Imported.`);
|
console.log(`${fileName} Imported.`);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on('error', (error) => {
|
.on('error', (error) => {
|
||||||
console.error(`Watcher error: ${error}`);
|
console.error(`Watcher error: ${error}`);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// readFileSync function must use __dirname get current directory
|
// readFileSync function must use __dirname get current directory
|
||||||
// require use ./ refer to current directory.
|
// require use ./ refer to current directory.
|
||||||
|
|
||||||
const options = {
|
const options = {};
|
||||||
};
|
|
||||||
|
|
||||||
var app = express()
|
var app = express()
|
||||||
|
|
||||||
// Create HTTPs server.
|
// Create HTTPs server.
|
||||||
|
|
||||||
//var httpsServer = https.createServer(options, app);
|
//var httpsServer = https.createServer(options, app);
|
||||||
|
|
||||||
@ -55,19 +55,19 @@ app.use(express.urlencoded({ extended: false }));
|
|||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
app.use(express.json({ extended: false }));
|
app.use(express.json({ extended: false }));
|
||||||
|
|
||||||
|
// define routes
|
||||||
app.use('/', indexRouter);
|
app.use('/', indexRouter);
|
||||||
app.use('/api/', apiRouter);
|
app.use('/api/', apiRouter);
|
||||||
|
|
||||||
// catch 404 and forward to error handler
|
// catch 404 and forward to error handler
|
||||||
app.use(function(req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
next(createError(404));
|
next(createError(404));
|
||||||
});
|
});
|
||||||
|
|
||||||
var PORT = process.env.PORT || 8000
|
var PORT = process.env.PORT || 8000
|
||||||
|
|
||||||
// error handler
|
// error handler
|
||||||
app.use(function(err, req, res, next) {
|
app.use(function (err, req, res, next) {
|
||||||
// set locals, only providing error in development
|
// set locals, only providing error in development
|
||||||
res.locals.message = err.message;
|
res.locals.message = err.message;
|
||||||
res.locals.error = req.app.get('env') === 'development' ? err : {};
|
res.locals.error = req.app.get('env') === 'development' ? err : {};
|
||||||
@ -77,6 +77,6 @@ app.use(function(err, req, res, next) {
|
|||||||
res.render('error');
|
res.render('error');
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(PORT, () => console.log(`Server is running in port ${PORT}`));
|
app.listen(PORT, () => console.log(`Server is running in port ${PORT}, Server type ${config.serverType}`));
|
||||||
|
|
||||||
module.exports = app;
|
module.exports = app;
|
44
readme.md
44
readme.md
@ -34,11 +34,53 @@ Create a `config.json` file and paste this in, with paths to your instance.
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"DXMemorialImageDirectory": "A:\\path\\to\\aqua\\data",
|
"serverType": 0,
|
||||||
|
"aquaSrvDir": "A:\\path\\to\\aqua\\data",
|
||||||
|
"ArtConnSettings": {
|
||||||
|
"host":"192.168.smt.hng",
|
||||||
|
"user":"MaiDXNet",
|
||||||
|
"pass":"aSecurePassword"
|
||||||
|
},
|
||||||
"imageFolder": "N:\\MaiMaiDXNet\\public\\images"
|
"imageFolder": "N:\\MaiMaiDXNet\\public\\images"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`serverType` selects between Aqua (0), and Artemis (1).
|
||||||
|
|
||||||
|
Note: you want to enter into the `data` folder in `aquaSrvDir`.
|
||||||
|
|
||||||
|
Note: `imageFolder` leads to the `/public/images` folder of the directory.
|
||||||
|
|
||||||
|
## Artemis
|
||||||
|
|
||||||
|
### WARNING: Artemis currently does not have support for Memorial Photos, and none will be imported when attempting to use Artemis.
|
||||||
|
|
||||||
|
Create a `config.json` file and paste this in, with paths to your instance.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"serverType": 1,
|
||||||
|
"aquaSrvDir": "A:\\path\\to\\aqua\\data",
|
||||||
|
"ArtConnSettings": {
|
||||||
|
"host":"192.168.smt.hng",
|
||||||
|
"user":"MaiDXNet",
|
||||||
|
"pass":"aSecurePassword"
|
||||||
|
},
|
||||||
|
"imageFolder": "N:\\MaiMaiDXNet\\public\\images"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`serverType` selects between Aqua (0), and Artemis (1).
|
||||||
|
|
||||||
|
Edit `ArtConnSettings` to be configured for your server.
|
||||||
|
|
||||||
|
Modify and use this command string in your terminal to create and set up permissions for The MaiDXNet account.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
CREATE USER 'MaiDXNet'@'%' IDENTIFIED BY 'aSecurePassword';
|
||||||
|
GRANT Alter,Create,Delete,Drop,Index,Insert,References,Select,Update ON aime.* TO 'MaiDXNet'@'%';
|
||||||
|
```
|
||||||
|
|
||||||
# Project Progress
|
# Project Progress
|
||||||
|
|
||||||
Goal for Milestone 1:
|
Goal for Milestone 1:
|
||||||
|
150
routes/api.js
150
routes/api.js
@ -1,126 +1,80 @@
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
var fetch = require('cross-fetch');
|
var fetch = require('cross-fetch');
|
||||||
const sqlite3 = require('sqlite3').verbose();
|
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
|
||||||
var config = require('../config.json');
|
var config = require('../config.json');
|
||||||
let db = new sqlite3.Database(config.DXMemorialImageDirectory + '\\db.sqlite');
|
var {getExtId,getUserArea,getUserScores,getUserUnbanned,getUserBanned, getUserData} = require("../dbhandler.js");
|
||||||
|
|
||||||
router.post('/getExtId/', function (req, res, next) {
|
router.post('/getExtId/', function (req, res, next) {
|
||||||
db.all('SELECT * FROM sega_card', (err, rows) => {
|
getExtId(req).then(
|
||||||
if (err) {
|
(mUser) => {
|
||||||
console.error(err);
|
res.status(200).json({ data: mUser, status: "Complete" });
|
||||||
// Return a Failed Message.
|
},
|
||||||
|
(reason) => {
|
||||||
res.status(500).json({ error: err.message, status: "Failed" });
|
res.status(500).json({ error: err.message, status: "Failed" });
|
||||||
} else {
|
console.error(reason); // Error!
|
||||||
// Make the Request easier to get to.
|
},
|
||||||
var request = req.body;
|
);
|
||||||
var mUser = undefined // Leave the Matched User undefined until the user is found.
|
|
||||||
for (user of rows) { // For Each User in Rows
|
|
||||||
if (request.input === user.luid) { // 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 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.
|
|
||||||
res.status(200).json({ data: mUser, status: "Complete" });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/getUserData/', function (req,res,next) {
|
router.post('/getUserData/', function (req,res,next) {
|
||||||
db.all('SELECT * FROM maimai2_user_detail', (err, rows) => {
|
getUserData(req).then(
|
||||||
if (err) {
|
(mUser) => {
|
||||||
console.error(err);
|
res.status(200).json({ data: mUser, status: "Complete" });
|
||||||
// Return a Failed Message.
|
},
|
||||||
|
(reason) => {
|
||||||
res.status(500).json({ error: err.message, status: "Failed" });
|
res.status(500).json({ error: err.message, status: "Failed" });
|
||||||
} else {
|
console.error(reason); // Error!
|
||||||
// Make the Request easier to get to.
|
},
|
||||||
var request = req.body;
|
);
|
||||||
var mUser = undefined // Leave the Matched User undefined until the user is found.
|
|
||||||
for (user of rows) { // For Each User in Rows
|
|
||||||
if (request.input === user.aime_card_id) { // 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 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.
|
|
||||||
res.status(200).json({ data: mUser, status: "Complete" });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
|
|
||||||
router.post('/getUserScores/', function (req,res,next) {
|
router.post('/getUserScores/', function (req,res,next) {
|
||||||
db.all('SELECT * FROM maimai2_user_playlog', (err, rows) => {
|
getUserScores(req).then(
|
||||||
if (err) {
|
(mUser) => {
|
||||||
console.error(err);
|
res.status(200).json({ data: mUser, status: "Complete" });
|
||||||
// Return a Failed Message.
|
},
|
||||||
res.status(500).json({ error: err.message, status: "Failed" });
|
(reason) => {
|
||||||
} else {
|
res.status(500).json({ error: err.message, status: "Failed" });
|
||||||
// Make the Request easier to get to.
|
console.error(reason); // Error!
|
||||||
var request = req.body;
|
},
|
||||||
var mUser = new Array(); // Leave the Matched User's Scores undefined until the user is found.
|
);
|
||||||
for (score of rows) { // For Each Score in Rows
|
|
||||||
if (request.input == score.user_id) { // If the inputed User ID and Score's User ID Matches,
|
|
||||||
mUser.push(score) // add that score into the array.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Return a Response with all the Scores listed under that user.
|
|
||||||
res.status(200).json({ data: mUser, status: "Complete" });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/getUserArea/', function (req,res,next) {
|
router.post('/getUserArea/', function (req,res,next) {
|
||||||
db.all('SELECT * FROM maimai2_user_map', (err, rows) => {
|
getUserArea(req).then(
|
||||||
if (err) {
|
(mUser) => {
|
||||||
console.error(err);
|
res.status(200).json({ data: mUser, status: "Complete" });
|
||||||
// Return a Failed Message.
|
},
|
||||||
|
(reason) => {
|
||||||
res.status(500).json({ error: err.message, status: "Failed" });
|
res.status(500).json({ error: err.message, status: "Failed" });
|
||||||
} else {
|
console.error(reason); // Error!
|
||||||
// Make the Request easier to get to.
|
},
|
||||||
var request = req.body;
|
);
|
||||||
var mUser = new Array(); // Leave the Matched User's Areas undefined until the user is found.
|
|
||||||
for (map of rows) { // For Each Area in Rows
|
|
||||||
if (request.input == map.user_id) { // If the inputed User ID and Score's User ID Matches,
|
|
||||||
mUser.push(map) // add that Area into the array.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Return a Response with all the Areas listed under that user.
|
|
||||||
res.status(200).json({ data: mUser, status: "Complete" });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/getuserbanned/', function (req,res,next) {
|
router.post('/getuserbanned/', function (req,res,next) {
|
||||||
var request = req.body;
|
getUserBanned(req).then(
|
||||||
if (request.input === undefined) {
|
(result) => {
|
||||||
return res.status(500).send('Failed to update user ban state, insufficent paramaters');
|
res.send(result);
|
||||||
}
|
},
|
||||||
db.run('UPDATE maimai2_user_detail SET ban_state = ? WHERE id = ?', [2, request.input], function(err) {
|
(reason) => {
|
||||||
if (err) {
|
res.status(500).send(reason);
|
||||||
console.error(err.message);
|
console.error(reason); // Error!
|
||||||
res.status(500).send('Failed to update user ban state');
|
},
|
||||||
} else {
|
);
|
||||||
res.send({"status": "Success", "message": `User ${request.input} banned.`});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/getuserunbanned/', function (req,res,next) {
|
router.post('/getuserunbanned/', function (req,res,next) {
|
||||||
var request = req.body;
|
getUserUnbanned(req).then(
|
||||||
if (request.input === undefined) {
|
(result) => {
|
||||||
return res.status(500).send('Failed to update user ban state, insufficent paramaters');
|
res.send(result);
|
||||||
}
|
},
|
||||||
db.run('UPDATE maimai2_user_detail SET ban_state = ? WHERE id = ?', [0, request.input], function(err) {
|
(reason) => {
|
||||||
if (err) {
|
res.status(500).send(reason);
|
||||||
console.error(err.message);
|
console.error(reason); // Error!
|
||||||
res.status(500).send('Failed to update user ban state');
|
},
|
||||||
} else {
|
);
|
||||||
res.send({"status": "Success", "message": `User ${request.input} unbanned.`});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/getmemorialimagelist/', function (req,res,next) {
|
router.get('/getmemorialimagelist/', function (req,res,next) {
|
||||||
|
@ -1,70 +1,38 @@
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
var fetch = require('cross-fetch');
|
var fetch = require('cross-fetch');
|
||||||
const sqlite3 = require('sqlite3').verbose();
|
|
||||||
var config = require('../config.json');
|
var config = require('../config.json');
|
||||||
let db = new sqlite3.Database(config.DXMemorialImageDirectory + '\\db.sqlite');
|
var { getUserCount, getUserData } = require("../dbhandler.js");
|
||||||
/* GET home page. */
|
/* GET home page. */
|
||||||
var title = 'MaiDXNet'
|
var title = 'MaiDXNet';
|
||||||
router.get('/', function (req, res, next) {
|
router.get('/', async function (req, res, next) {
|
||||||
db.all('SELECT * FROM sega_card', (err, rows) => {
|
var usersRegistered = await getUserCount().then(
|
||||||
if (err) {
|
(userCount) => {
|
||||||
console.error(err);
|
|
||||||
res.render('error', { error: err });
|
|
||||||
} else {
|
|
||||||
console.log(rows);
|
|
||||||
console.log(`There are Currently ${rows.length} Users Registered.`); // this check could probably be changed into an API
|
|
||||||
var params = {
|
var params = {
|
||||||
totalUsers: rows.length
|
totalUsers: userCount // ToDo: Change this to use the internal dbhandler api
|
||||||
}
|
};
|
||||||
|
console.log(`Recived User Count:`+userCount)
|
||||||
res.render('index', { title: title, params: params });
|
res.render('index', { title: title, params: params });
|
||||||
}
|
},
|
||||||
});
|
(reason) => {
|
||||||
|
res.render('error', { title: title, error: reason });
|
||||||
|
console.error(reason); // Error!
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
router.get('/user', async function (req, res, next) {
|
router.get('/user', async function (req, res, next) {
|
||||||
try{
|
try {
|
||||||
const cookies = req.cookies
|
const cookies = req.cookies
|
||||||
console.log(cookies)
|
console.log(cookies)
|
||||||
if (cookies.aime_card_id === undefined) {
|
if (cookies.aime_card_id === undefined) {
|
||||||
return res.redirect("/")
|
return res.redirect("/")
|
||||||
}
|
}
|
||||||
res.render('user', { title: title, userdata: await getUserData(req) });
|
res.render('user', { title: title, userdata: await getUserData(req) });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.render('error', { error: err });
|
res.render('error', { error: err });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
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) => {
|
|
||||||
if (err) {
|
|
||||||
console.error(err);
|
|
||||||
// Return a Failed Message.
|
|
||||||
reject(err)
|
|
||||||
} 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'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} // function is required to obtain the User Data, and create the user profile. I'm going to bed.
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
Loading…
Reference in New Issue
Block a user