diff --git a/front/src/ctfnote/parsers/index.ts b/front/src/ctfnote/parsers/index.ts index add3bdce..57b3dea0 100644 --- a/front/src/ctfnote/parsers/index.ts +++ b/front/src/ctfnote/parsers/index.ts @@ -6,6 +6,7 @@ import justCTFParser from './justctf'; import AngstromParser from './angstrom'; import CINIParser from './cini'; import HitconParser from './hitcon'; +import KITCTFParser from './kitctf'; export type ParsedTask = { title: string; @@ -29,4 +30,5 @@ export default [ AngstromParser, CINIParser, HitconParser, + KITCTFParser, ]; diff --git a/front/src/ctfnote/parsers/kitctf.ts b/front/src/ctfnote/parsers/kitctf.ts new file mode 100644 index 00000000..d9a5f900 --- /dev/null +++ b/front/src/ctfnote/parsers/kitctf.ts @@ -0,0 +1,31 @@ +import { ParsedTask, Parser } from '.'; +import { parseJsonStrict } from '../utils'; + +const KITCTFParser: Parser = { + name: 'KITCTF parser', + hint: 'paste /api/challenges', + + parse(s: string): ParsedTask[] { + const tasks = []; + const data = + parseJsonStrict< + Array<{ name: string; tags: string[]; description: string }> + >(s); + if (!Array.isArray(data)) { + return []; + } + for (const task of data) { + if (!task.name || !task.tags) { + continue; + } + tasks.push({ + title: task.name, + tags: task.tags, + description: task.description, + }); + } + return tasks; + }, +}; + +export default KITCTFParser;