further benchmarking stuff
This commit is contained in:
@@ -1,35 +1,43 @@
|
||||
import { defineEventHandler } from 'h3'
|
||||
import { ChallengeStrategy } from '@impost/lib';
|
||||
import { ChallengeStrategy, ChallengeAlgorithm } 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',
|
||||
});
|
||||
}
|
||||
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;
|
||||
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 ChallengeStrategy.TargetNumber:
|
||||
if (!difficulty || difficulty < 1 || difficulty > 100_000_000) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Invalid request',
|
||||
});
|
||||
}
|
||||
|
||||
config.target_number.max_number = difficulty;
|
||||
case ChallengeAlgorithm.kCTF:
|
||||
config.kctf.difficulty = difficulty;
|
||||
break;
|
||||
}
|
||||
|
||||
return {
|
||||
message: 'Challenge difficulty set'
|
||||
message: `Challenge difficulty set to ${difficulty}`
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user