Merge branch 'master' of git.rezo-rm.fr:BDEMetz/bde-liste

This commit is contained in:
johan 2023-01-10 09:34:12 +01:00
commit 2aa03b8582

View file

@ -9,6 +9,7 @@ var prankPath = "prankdata.txt";
var activityPath = "activitydata.txt";
var treasurePath = "treasuredata.txt";
var goldenUsersPath = "goldenusers.txt";
var servicePath = "servicestate.txt";
initFs();
@ -18,6 +19,7 @@ let PrankData = JSON.parse(fs.readFileSync(prankPath));
let ActivityData = JSON.parse(fs.readFileSync(activityPath));
let TreasureData = JSON.parse(fs.readFileSync(treasurePath));
let GoldenUsers = JSON.parse(fs.readFileSync(goldenUsersPath));
let ServiceState = JSON.parse(fs.readFileSync(servicePath));
let AdminUsersUid = ["asyncnomi", "johan", "enthalpine", "fleur", "arina", "billy", "remi", "pierre", "matmaz", "mariusdrgc", "agathe", "jsansa"];
let UsersToken = {};
let TokenDurationSecond = 3600;
@ -135,6 +137,32 @@ fastify.post('/register', async (request, reply) => {
}
})
fastify.post('/switchState', async (request, reply) => {
let content = request.body;
let auth = checkAuthetification(content);
if (auth.success) {
if (AdminUsersUid.includes(content.uid)) {
if (ServiceState.state == "closed") {
ServiceState.state = "open";
} else {
ServiceState.state = "closed";
}
saveData(servicePath, ServiceState);
return {
success: true,
state: ServiceState.state
}
} else {
return {
success: false,
why: "Not allowed"
}
}
} else {
return auth
}
})
fastify.post('/addPrank', async (request, reply) => {
let content = request.body;
let auth = checkAuthetification(content);
@ -384,6 +412,12 @@ fastify.post('/get', async (request, reply) => {
}
}
break;
case "state":
return {
success: true,
state: ServiceState.state
}
break;
default:
return {
success: false,
@ -759,6 +793,9 @@ function initFs() {
if (!fs.existsSync(goldenUsersPath)) {
fs.writeFileSync(goldenUsersPath, "{}");
}
if (!fs.existsSync(servicePath)) {
fs.writeFileSync(servicePath, JSON.stringify({state: 'closed'}));
}
if (!fs.existsSync("static/images")){
fs.mkdirSync("static/images");
}