Browse Source

bla

pull/1/head
asyncnomi 3 years ago
parent
commit
b5f9234c44
  1. 74
      index.js

74
index.js

@ -300,7 +300,7 @@ fastify.post('/get', async (request, reply) => {
case "activity": case "activity":
return { return {
sucess: true, sucess: true,
prankData: ActivityData activityData: ActivityData
} }
break; break;
default: default:
@ -325,37 +325,46 @@ fastify.post('/addActivity', async (request, reply) => {
let auth = checkAuthetification(content); let auth = checkAuthetification(content);
if (auth.success) { if (auth.success) {
if (AdminUsersUid.includes(content.uid)) { if (AdminUsersUid.includes(content.uid)) {
if ("title" in content if ("type" in content
&& "title" in content
&& "desc" in content && "desc" in content
&& "start" in content && "start" in content
&& "end" in content && "end" in content
&& "where" in content) { && "where" in content) {
let activityUid = makeid(16); if (["event", "treasure"].contains(content.type)) {
if ("activityUid" in content) { let activityUid = makeid(16);
let activityExists = checkActivity(content) if ("activityUid" in content) {
if (activityExists.success) { let activityExists = checkActivity(content)
activityUid = content.activityUid; if (activityExists.success) {
} else { activityUid = content.activityUid;
return activityExists; } 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 { } else {
return { return {
success: false, success: false,
why: "Missing title, desc, start, end or where" why: "Missing type, title, desc, start, end or where"
} }
} }
} else { } 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) { function saveData(path, data) {
fs.writeFileSync(path, JSON.stringify(data)); fs.writeFileSync(path, JSON.stringify(data));
@ -431,7 +455,7 @@ function checkAuthetification(content) {
} else { } else {
return { return {
success: false, success: false,
why: "Not authenticated" why: "Not authentificated"
} }
} }
} }
@ -504,7 +528,7 @@ function makeid(length) {
var result = ''; var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length; 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)); result += characters.charAt(Math.floor(Math.random() * charactersLength));
} }
return result; return result;

Loading…
Cancel
Save