43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { defineEventHandler } from 'h3'
|
|
import { ChallengeStrategy, ChallengeAlgorithm } from '@impost/lib';
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const body = await readBody(event)
|
|
|
|
let difficulty = body.difficulty;
|
|
|
|
switch (config.algorithm) {
|
|
case ChallengeAlgorithm.SHA256:
|
|
case ChallengeAlgorithm.Argon2:
|
|
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;
|
|
}
|
|
break;
|
|
case ChallengeAlgorithm.kCTF:
|
|
config.kctf.difficulty = difficulty;
|
|
break;
|
|
}
|
|
|
|
return {
|
|
message: `Challenge difficulty set to ${difficulty}`
|
|
};
|
|
}); |