Clean up code. Reorganize files. Port stuff from other branches. + more
This turns the project into a monorepo using pnpm workspaces, dramatically simplifying the build process. It also fixes a lot of bugs and just generally makes the codebase a lot cleaner.
This commit is contained in:
@@ -13,26 +13,29 @@ export default defineEventHandler(async (event) => {
|
||||
const body = await readValidatedBody(event, challengeSchema.safeParse);
|
||||
|
||||
if (!body.success) {
|
||||
const errors = z.treeifyError(body.error);
|
||||
const error_message = Object.entries(errors.errors).map(([key, value]) => `${key}: ${value}`).join('\n');
|
||||
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Validation failed'
|
||||
statusMessage: error_message
|
||||
})
|
||||
}
|
||||
|
||||
let target = body.data.challenge;
|
||||
let nonce = body.data.nonce;
|
||||
let { challenge, nonce } = body.data;
|
||||
|
||||
const outstanding_challenge = outstandingChallenges.get(body.data.challenge)!;
|
||||
// always delete the challenge on a solve attempt
|
||||
clearTimeout(outstanding_challenge.timeout);
|
||||
outstandingChallenges.delete(challenge);
|
||||
|
||||
// check if the challenge is valid
|
||||
let challenge_valid = await validate_challenge(outstandingChallenges.get(target)!.challenge, {
|
||||
challenge: target,
|
||||
nonce: nonce
|
||||
let challenge_valid = await validate_challenge(outstandingChallenges.get(challenge)!.challenge, {
|
||||
challenge,
|
||||
nonce,
|
||||
});
|
||||
|
||||
if (challenge_valid) {
|
||||
// clear the challenge
|
||||
clearTimeout(outstandingChallenges.get(target)!.timeout);
|
||||
outstandingChallenges.delete(target);
|
||||
|
||||
return {
|
||||
message: 'Challenge solved'
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user