Files
impost/example-app/server/api/pow/difficulty.put.ts
Zoe cfab3d0b8f Initial commit
Once again a weird place to commit, I have already done a lot of work, but I am just bad at using git, okay.
2025-11-17 16:12:26 +00:00

35 lines
1.0 KiB
TypeScript

import { defineEventHandler } from 'h3'
import { ChallengeStrategy } from '@impost/lib';
export default defineEventHandler(async (event) => {
const body = await readBody(event)
let difficulty = body.difficulty;
switch (config.strategy) {
case ChallengeStrategy.LeadingZeroes:
if (!difficulty || difficulty < 1 || difficulty > 64) {
throw createError({
statusCode: 400,
statusMessage: 'Invalid request',
});
}
config.leading_zeroes.difficulty = difficulty;
break;
case ChallengeStrategy.TargetNumber:
if (!difficulty || difficulty < 1 || difficulty > 100_000_000) {
throw createError({
statusCode: 400,
statusMessage: 'Invalid request',
});
}
config.target_number.max_number = difficulty;
break;
}
return {
message: 'Challenge difficulty set'
};
});