2023-02-17 00:50:32 +01:00
|
|
|
var express = require('express');
|
|
|
|
var router = express.Router();
|
|
|
|
var fetch = require('cross-fetch');
|
2023-05-24 18:19:35 +02:00
|
|
|
const fs = require('fs')
|
2023-05-07 07:20:04 +02:00
|
|
|
var config = require('../config.json');
|
2023-07-16 10:06:49 +02:00
|
|
|
var {getExtId,getUserArea,getUserScores,getUserUnbanned,getUserBanned, getUserData} = require("../dbhandler.js");
|
2023-02-17 00:50:32 +01:00
|
|
|
|
|
|
|
router.post('/getExtId/', function (req, res, next) {
|
2023-07-16 10:06:49 +02:00
|
|
|
getExtId(req).then(
|
|
|
|
(mUser) => {
|
|
|
|
res.status(200).json({ data: mUser, status: "Complete" });
|
|
|
|
},
|
|
|
|
(reason) => {
|
2023-07-17 04:54:56 +02:00
|
|
|
res.status(500).json({ error: reason, status: "Failed" });
|
2023-07-16 10:06:49 +02:00
|
|
|
console.error(reason); // Error!
|
|
|
|
},
|
|
|
|
);
|
2023-02-17 00:50:32 +01:00
|
|
|
});
|
|
|
|
|
2023-02-17 02:43:12 +01:00
|
|
|
router.post('/getUserData/', function (req,res,next) {
|
2023-07-16 10:06:49 +02:00
|
|
|
getUserData(req).then(
|
|
|
|
(mUser) => {
|
|
|
|
res.status(200).json({ data: mUser, status: "Complete" });
|
|
|
|
},
|
|
|
|
(reason) => {
|
2023-07-17 04:54:56 +02:00
|
|
|
res.status(500).json({ error: reason, status: "Failed" });
|
2023-07-16 10:06:49 +02:00
|
|
|
console.error(reason); // Error!
|
|
|
|
},
|
|
|
|
);
|
2023-02-17 02:43:12 +01:00
|
|
|
})
|
|
|
|
|
2023-02-18 11:19:30 +01:00
|
|
|
router.post('/getUserScores/', function (req,res,next) {
|
2023-07-16 10:06:49 +02:00
|
|
|
getUserScores(req).then(
|
|
|
|
(mUser) => {
|
|
|
|
res.status(200).json({ data: mUser, status: "Complete" });
|
|
|
|
},
|
|
|
|
(reason) => {
|
|
|
|
res.status(500).json({ error: err.message, status: "Failed" });
|
|
|
|
console.error(reason); // Error!
|
|
|
|
},
|
|
|
|
);
|
2023-02-18 11:19:30 +01:00
|
|
|
});
|
2023-02-17 03:49:08 +01:00
|
|
|
|
2023-02-25 14:30:21 +01:00
|
|
|
router.post('/getUserArea/', function (req,res,next) {
|
2023-07-16 10:06:49 +02:00
|
|
|
getUserArea(req).then(
|
|
|
|
(mUser) => {
|
|
|
|
res.status(200).json({ data: mUser, status: "Complete" });
|
|
|
|
},
|
|
|
|
(reason) => {
|
2023-02-25 14:30:21 +01:00
|
|
|
res.status(500).json({ error: err.message, status: "Failed" });
|
2023-07-16 10:06:49 +02:00
|
|
|
console.error(reason); // Error!
|
|
|
|
},
|
|
|
|
);
|
2023-02-25 14:30:21 +01:00
|
|
|
});
|
2023-02-17 03:49:08 +01:00
|
|
|
|
2023-05-07 07:20:04 +02:00
|
|
|
router.post('/getuserbanned/', function (req,res,next) {
|
2023-07-16 10:06:49 +02:00
|
|
|
getUserBanned(req).then(
|
|
|
|
(result) => {
|
|
|
|
res.send(result);
|
|
|
|
},
|
|
|
|
(reason) => {
|
|
|
|
res.status(500).send(reason);
|
|
|
|
console.error(reason); // Error!
|
|
|
|
},
|
|
|
|
);
|
2023-05-07 07:20:04 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
router.post('/getuserunbanned/', function (req,res,next) {
|
2023-07-16 10:06:49 +02:00
|
|
|
getUserUnbanned(req).then(
|
|
|
|
(result) => {
|
|
|
|
res.send(result);
|
|
|
|
},
|
|
|
|
(reason) => {
|
|
|
|
res.status(500).send(reason);
|
|
|
|
console.error(reason); // Error!
|
|
|
|
},
|
|
|
|
);
|
2023-05-07 07:20:04 +02:00
|
|
|
});
|
2023-05-24 18:19:35 +02:00
|
|
|
|
|
|
|
router.get('/getmemorialimagelist/', function (req,res,next) {
|
2023-07-17 08:16:54 +02:00
|
|
|
let ext = ".jpg";
|
|
|
|
let ext2 = ".jpeg";
|
2023-05-24 18:19:35 +02:00
|
|
|
// Use fs.readdirSync() to get the file names synchronously
|
2023-07-17 08:16:54 +02:00
|
|
|
const files = fs.readdirSync(config.imageFolder);
|
2023-05-24 18:19:35 +02:00
|
|
|
// Filter the files by extension and create an array of names
|
2023-07-17 08:16:54 +02:00
|
|
|
const imageNames = files.filter(file => file.endsWith('.jpg') || file.endsWith('.jpeg')).map(file => file.endsWith('.jpeg') ? file.slice(0, -5) : file.slice(0, -4));
|
|
|
|
|
2023-05-24 18:19:35 +02:00
|
|
|
// Create and return a JSON object with the image names
|
|
|
|
res.send(imageNames);
|
|
|
|
});
|
|
|
|
|
2023-02-17 00:50:32 +01:00
|
|
|
module.exports = router;
|