diff --git a/front/src/ctfnote/parsers/hitcon.ts b/front/src/ctfnote/parsers/hitcon.ts new file mode 100644 index 000000000..464916013 --- /dev/null +++ b/front/src/ctfnote/parsers/hitcon.ts @@ -0,0 +1,47 @@ +import { ParsedTask, Parser } from '.'; +import { parseJsonStrict } from '../utils'; + +const HitconParser: Parser = { + name: 'HITCONCTF parser', + hint: 'paste hitcon /dashboard/challenge_data', + parse(s): ParsedTask[] { + const tasks: ParsedTask[] = []; + const data = + parseJsonStrict< + [{ name: string; category: string; description: string }] + >(s); + if (data == null) { + return []; + } + + for (const challenge of data) { + if (!challenge.description || !challenge.name) { + continue; + } + + tasks.push({ + title: challenge.name, + tags: challenge.category.split(','), + description: challenge.description, + }); + } + + return tasks; + }, + isValid(s) { + const data = + parseJsonStrict< + [{ name: string; category: string; description: string }] + >(s); + if (data == null || data.length < 1) { + return false; + } + return ( + data[0].name != null && + data[0].category != null && + data[0].description != null + ); + }, +}; + +export default HitconParser; diff --git a/front/src/ctfnote/parsers/index.ts b/front/src/ctfnote/parsers/index.ts index a2ec5ab97..0daef8bd9 100644 --- a/front/src/ctfnote/parsers/index.ts +++ b/front/src/ctfnote/parsers/index.ts @@ -5,6 +5,7 @@ import HTBParser from './htb'; import PicoParser from './pico'; import justCTFParser from './justctf'; import AngstromParser from './angstrom'; +import HitconParser from './hitcon'; export type ParsedTask = { title: string; @@ -28,4 +29,5 @@ export default [ PicoParser, justCTFParser, AngstromParser, + HitconParser, ];