further benchmarking stuff
This commit is contained in:
43
example-app/server/api/pow/strategy.put.ts
Normal file
43
example-app/server/api/pow/strategy.put.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { defineEventHandler } from 'h3'
|
||||
import { ChallengeAlgorithm, ChallengeStrategy } from '@impost/lib';
|
||||
import * as z from 'zod';
|
||||
|
||||
const strategySchema = z.object({
|
||||
strategy: z.enum(ChallengeStrategy),
|
||||
});
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readValidatedBody(event, strategySchema.safeParse);
|
||||
|
||||
if (!body.success) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Validation failed'
|
||||
})
|
||||
}
|
||||
|
||||
switch (config.algorithm) {
|
||||
case ChallengeAlgorithm.SHA256:
|
||||
case ChallengeAlgorithm.Argon2:
|
||||
config.strategy = body.data.strategy;
|
||||
switch (config.strategy) {
|
||||
case ChallengeStrategy.LeadingZeroes:
|
||||
config.leading_zeroes = config.leading_zeroes || {};
|
||||
config.leading_zeroes.difficulty = config.leading_zeroes.difficulty || 4;
|
||||
break;
|
||||
case ChallengeStrategy.TargetNumber:
|
||||
config.target_number = config.target_number || {};
|
||||
config.target_number.max_number = config.target_number.max_number || 10_000;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ChallengeAlgorithm.kCTF:
|
||||
return {
|
||||
message: "Strategy cannot be set for kCTF"
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
message: `Strategy set to ${config.strategy}`
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user