diff --git a/front/src/ctfnote/parsers/ecsc.ts b/front/src/ctfnote/parsers/ecsc.ts new file mode 100644 index 000000000..a487ce536 --- /dev/null +++ b/front/src/ctfnote/parsers/ecsc.ts @@ -0,0 +1,29 @@ +import { ParsedTask, Parser } from '.'; +import { parseJson, parseJsonStrict } from '../utils'; + +const ECSCParser: Parser = { + name: 'ECSC parser', + hint: 'paste ecsc /stats.json', + + parse(s: string): ParsedTask[] { + const tasks = []; + const data = parseJsonStrict<[{ task: string; contract: string }]>(s); + if (!Array.isArray(data)) { + return []; + } + + for (const task of data) { + if (!task.task || !task.contract) { + continue; + } + tasks.push({ title: task.task, category: task.contract }); + } + return tasks; + }, + isValid(s) { + const data = parseJson<[{ task: string; contract: string }]>(s); + return Array.isArray(data); + }, +}; + +export default ECSCParser; diff --git a/front/src/ctfnote/parsers/index.ts b/front/src/ctfnote/parsers/index.ts index f23d010bf..cf9181058 100644 --- a/front/src/ctfnote/parsers/index.ts +++ b/front/src/ctfnote/parsers/index.ts @@ -1,4 +1,5 @@ import CTFDParser from './ctfd'; +import ECSCParser from './ecsc'; import RawParser from './raw'; export type ParsedTask = { @@ -13,4 +14,4 @@ export type Parser = { parse(s: string): ParsedTask[]; }; -export default [RawParser, CTFDParser]; +export default [RawParser, CTFDParser, ECSCParser];