1
0
mirror of https://dev.s-ul.net/Galexion/MaiMaiDXNet.git synced 2024-11-27 22:50:48 +01:00
MaiMaiDXNet/routes/api.js

92 lines
2.6 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');
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');
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) {
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" });
console.error(reason); // Error!
},
);
2023-02-17 00:50:32 +01:00
});
router.post('/getUserData/', function (req,res,next) {
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" });
console.error(reason); // Error!
},
);
})
2023-02-18 11:19:30 +01:00
router.post('/getUserScores/', function (req,res,next) {
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-25 14:30:21 +01:00
router.post('/getUserArea/', function (req,res,next) {
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" });
console.error(reason); // Error!
},
);
2023-02-25 14:30:21 +01:00
});
2023-05-07 07:20:04 +02:00
router.post('/getuserbanned/', function (req,res,next) {
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) {
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) {
let ext = ".jpg";
let ext2 = ".jpeg";
2023-05-24 18:19:35 +02:00
// Use fs.readdirSync() to get the file names synchronously
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
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;