This commit is contained in:
asyncnomi 2023-01-10 09:17:52 +01:00
parent 2d15d097bd
commit 3b596472de

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,25 @@ fastify.post('/register', async (request, reply) => {
}
})
fastify.post('/switchState', async (request, reply) => {
let content = request.body;
let auth = checkAuthetification(content);
if (auth.success) {
if (ServiceState.state == "closed") {
ServiceState.state = "open";
} else {
ServiceState.state = "closed";
}
saveData(servicePath, ServiceState);
return {
success: true,
state: ServiceState.state
}
} else {
return auth
}
})
fastify.post('/addPrank', async (request, reply) => {
let content = request.body;
let auth = checkAuthetification(content);
@ -759,6 +780,9 @@ function initFs() {
if (!fs.existsSync(goldenUsersPath)) {
fs.writeFileSync(goldenUsersPath, "{}");
}
if (!fs.existsSync(servicePath)) {
fs.writeFileSync(servicePath, "{state: 'closed'}");
}
if (!fs.existsSync("static/images")){
fs.mkdirSync("static/images");
}