|
|
|
@ -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; |
|
|
|
|