From 3b596472debc1c16a747e389fc34effbe2309c64 Mon Sep 17 00:00:00 2001 From: asyncnomi Date: Tue, 10 Jan 2023 09:17:52 +0100 Subject: [PATCH] bla --- index.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/index.js b/index.js index 6b42c4f..61113ed 100644 --- a/index.js +++ b/index.js @@ -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"); }