From b5f9234c44c40db0eae6781516dbe1884b2afc25 Mon Sep 17 00:00:00 2001 From: asyncnomi Date: Thu, 15 Dec 2022 14:34:25 +0100 Subject: [PATCH] bla --- index.js | 74 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/index.js b/index.js index d9a08d0..56d59f6 100644 --- a/index.js +++ b/index.js @@ -300,7 +300,7 @@ fastify.post('/get', async (request, reply) => { case "activity": return { sucess: true, - prankData: ActivityData + activityData: ActivityData } break; default: @@ -325,37 +325,46 @@ fastify.post('/addActivity', async (request, reply) => { let auth = checkAuthetification(content); if (auth.success) { if (AdminUsersUid.includes(content.uid)) { - if ("title" in content + if ("type" in content + && "title" in content && "desc" in content && "start" in content && "end" in content && "where" in content) { - let activityUid = makeid(16); - if ("activityUid" in content) { - let activityExists = checkActivity(content) - if (activityExists.success) { - activityUid = content.activityUid; - } else { - return activityExists; + if (["event", "treasure"].contains(content.type)) { + let activityUid = makeid(16); + if ("activityUid" in content) { + let activityExists = checkActivity(content) + if (activityExists.success) { + activityUid = content.activityUid; + } else { + return activityExists; + } + } + ActivityData[activityUid] = { + type: content.type, + title: content.title, + desc: content.desc, + start: content.start, + end: content.end, + where: content.where + } + saveData(activityPath, ActivityData); + return { + sucess: true, + uid: activityUid, + activity: ActivityData[activityUid] + } + } else { + return { + success: false, + why: "Unkonw type" } - } - ActivityData[activityUid] = { - title: content.title, - desc: content.desc, - start: content.start, - end: content.end, - where: content.where - } - saveData(activityPath, ActivityData); - return { - sucess: true, - uid: activityUid, - activity: ActivityData[activityUid] } } else { return { success: false, - why: "Missing title, desc, start, end or where" + why: "Missing type, title, desc, start, end or where" } } } else { @@ -389,6 +398,21 @@ fastify.post('/delActivity', async (request, reply) => { } }) +fastify.post('/sendTreasure', async (request, reply) => { + let content = request.body; + let auth = checkAuthetification(content); + if (auth.success) { + let activityExists = checkActivity(content) + if (activityExists.success) { + + } else { + return activityExists + } + } else { + return auth + } +}) + function saveData(path, data) { fs.writeFileSync(path, JSON.stringify(data)); @@ -431,7 +455,7 @@ function checkAuthetification(content) { } else { return { success: false, - why: "Not authenticated" + why: "Not authentificated" } } } @@ -504,7 +528,7 @@ function makeid(length) { var result = ''; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var charactersLength = characters.length; - for ( var i = 0; i < length; i++ ) { + for (var i = 0; i < length; i++) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result;