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

92 lines
2.6 KiB
JavaScript

var express = require('express');
var router = express.Router();
var fetch = require('cross-fetch');
const fs = require('fs')
var config = require('../config.json');
var {getExtId,getUserArea,getUserScores,getUserUnbanned,getUserBanned, getUserData} = require("../dbhandler.js");
router.post('/getExtId/', function (req, res, next) {
getExtId(req).then(
(mUser) => {
res.status(200).json({ data: mUser, status: "Complete" });
},
(reason) => {
res.status(500).json({ error: reason, status: "Failed" });
console.error(reason); // Error!
},
);
});
router.post('/getUserData/', function (req,res,next) {
getUserData(req).then(
(mUser) => {
res.status(200).json({ data: mUser, status: "Complete" });
},
(reason) => {
res.status(500).json({ error: reason, status: "Failed" });
console.error(reason); // Error!
},
);
})
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!
},
);
});
router.post('/getUserArea/', function (req,res,next) {
getUserArea(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!
},
);
});
router.post('/getuserbanned/', function (req,res,next) {
getUserBanned(req).then(
(result) => {
res.send(result);
},
(reason) => {
res.status(500).send(reason);
console.error(reason); // Error!
},
);
});
router.post('/getuserunbanned/', function (req,res,next) {
getUserUnbanned(req).then(
(result) => {
res.send(result);
},
(reason) => {
res.status(500).send(reason);
console.error(reason); // Error!
},
);
});
router.get('/getmemorialimagelist/', function (req,res,next) {
let ext = ".jpg";
let ext2 = ".jpeg";
// Use fs.readdirSync() to get the file names synchronously
const files = fs.readdirSync(config.imageFolder);
// 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));
// Create and return a JSON object with the image names
res.send(imageNames);
});
module.exports = router;