Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ECSC task parser #184

Merged
merged 1 commit into from
Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions front/src/ctfnote/parsers/ecsc.ts
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion front/src/ctfnote/parsers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CTFDParser from './ctfd';
import ECSCParser from './ecsc';
import RawParser from './raw';

export type ParsedTask = {
Expand All @@ -13,4 +14,4 @@ export type Parser = {
parse(s: string): ParsedTask[];
};

export default [RawParser, CTFDParser];
export default [RawParser, CTFDParser, ECSCParser];