From 9314edf0967db5991d2fdcd82469b850189d94f9 Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Tue, 11 Jul 2023 08:01:41 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Add=20=C3=A5ngstromCTF=20parser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parsing challenges from https://angstromctf.com/ --- front/src/ctfnote/parsers/angstrom.ts | 44 +++++++++++++++++++++++++++ front/src/ctfnote/parsers/index.ts | 2 ++ 2 files changed, 46 insertions(+) create mode 100644 front/src/ctfnote/parsers/angstrom.ts diff --git a/front/src/ctfnote/parsers/angstrom.ts b/front/src/ctfnote/parsers/angstrom.ts new file mode 100644 index 000000000..1ddd1445e --- /dev/null +++ b/front/src/ctfnote/parsers/angstrom.ts @@ -0,0 +1,44 @@ +import { ParsedTask, Parser } from '.'; +import { parseJson, parseJsonStrict } from '../utils'; + +const AngstromParser: Parser = { + name: 'ångstromCTF parser', + hint: 'paste api.angstromctf.com/competitions/XX/challenges with XX being the event id', + + parse(s: string): ParsedTask[] { + const tasks = []; + const data = + parseJsonStrict< + Array<{ title: string; category: string; description: string }> + >(s); + if (!Array.isArray(data)) { + return []; + } + for (const task of data) { + if (!task.title || !task.category) { + continue; + } + tasks.push({ + title: task.title, + category: task.category, + description: task.description, + }); + } + return tasks; + }, + isValid(s) { + const data = + parseJson< + Array<{ title: string; category: string; description: string }> + >(s); + return ( + Array.isArray(data) && + data.length > 0 && + data[0].title != null && + data[0].category != null && + data[0].description != null + ); + }, +}; + +export default AngstromParser; diff --git a/front/src/ctfnote/parsers/index.ts b/front/src/ctfnote/parsers/index.ts index a6e010eda..a2ec5ab97 100644 --- a/front/src/ctfnote/parsers/index.ts +++ b/front/src/ctfnote/parsers/index.ts @@ -4,6 +4,7 @@ import RawParser from './raw'; import HTBParser from './htb'; import PicoParser from './pico'; import justCTFParser from './justctf'; +import AngstromParser from './angstrom'; export type ParsedTask = { title: string; @@ -26,4 +27,5 @@ export default [ HTBParser, PicoParser, justCTFParser, + AngstromParser, ]; From 2399f4f0669632f3e1740712f80522495a329283 Mon Sep 17 00:00:00 2001 From: JJ-8 <34778827+JJ-8@users.noreply.github.com> Date: Thu, 14 Sep 2023 19:37:55 +0200 Subject: [PATCH 2/2] Make angstrom parser tags compatible --- front/src/ctfnote/parsers/angstrom.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/src/ctfnote/parsers/angstrom.ts b/front/src/ctfnote/parsers/angstrom.ts index 1ddd1445e..d31580575 100644 --- a/front/src/ctfnote/parsers/angstrom.ts +++ b/front/src/ctfnote/parsers/angstrom.ts @@ -20,7 +20,7 @@ const AngstromParser: Parser = { } tasks.push({ title: task.title, - category: task.category, + tags: [task.category], description: task.description, }); }