From d6e66b4c6a25e8a36db3455191185e7976ff7cc5 Mon Sep 17 00:00:00 2001 From: Daan Breur Date: Sat, 13 Jul 2024 12:00:45 +0200 Subject: [PATCH 1/4] Add base of the hitcon parser for ctfnote --- front/src/ctfnote/parsers/hitcon.ts | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 front/src/ctfnote/parsers/hitcon.ts diff --git a/front/src/ctfnote/parsers/hitcon.ts b/front/src/ctfnote/parsers/hitcon.ts new file mode 100644 index 000000000..206fe701c --- /dev/null +++ b/front/src/ctfnote/parsers/hitcon.ts @@ -0,0 +1,33 @@ +import { ParsedTask, Parser } from '.'; + +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); + return Array.isArray(data); + }, +}; + +export default HitconParser; From 2be3205b45100b808989d130ef209c1774d51fad Mon Sep 17 00:00:00 2001 From: Daan Breur Date: Sat, 13 Jul 2024 12:01:25 +0200 Subject: [PATCH 2/4] import hitcon parser --- front/src/ctfnote/parsers/index.ts | 2 ++ 1 file changed, 2 insertions(+) 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, ]; From d869facd4ce9d5bc533759c47ea67c40c421c453 Mon Sep 17 00:00:00 2001 From: JJ-8 <34778827+JJ-8@users.noreply.github.com> Date: Sun, 14 Jul 2024 21:00:44 +0200 Subject: [PATCH 3/4] Fix HITCON parser The isValid function has been updated to match the correct data and imports are fixed. --- front/src/ctfnote/parsers/hitcon.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/front/src/ctfnote/parsers/hitcon.ts b/front/src/ctfnote/parsers/hitcon.ts index 206fe701c..e8eaf65c9 100644 --- a/front/src/ctfnote/parsers/hitcon.ts +++ b/front/src/ctfnote/parsers/hitcon.ts @@ -1,11 +1,15 @@ 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); + const data = + parseJsonStrict< + [{ name: string; category: string; description: string }] + >(s); if (data == null) { return []; } @@ -14,10 +18,10 @@ const HitconParser: Parser = { if (!challenge.description || !challenge.name) { continue; } - + tasks.push({ title: challenge.name, - tags: challenge.category.split(","), + tags: challenge.category.split(','), description: challenge.description, }); } @@ -25,8 +29,18 @@ const HitconParser: Parser = { return tasks; }, isValid(s) { - const data = parseJsonStrict<[{ name: string; category: string; description: string }]>(s); - return Array.isArray(data); + 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 + ); }, }; From bd64f92e99e55d5ed5b8ca5c3b3a193c0cf6514e Mon Sep 17 00:00:00 2001 From: JJ-8 <34778827+JJ-8@users.noreply.github.com> Date: Sun, 14 Jul 2024 21:05:12 +0200 Subject: [PATCH 4/4] Fix formatting issues in hitcon.ts --- front/src/ctfnote/parsers/hitcon.ts | 94 ++++++++++++++--------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/front/src/ctfnote/parsers/hitcon.ts b/front/src/ctfnote/parsers/hitcon.ts index e8eaf65c9..464916013 100644 --- a/front/src/ctfnote/parsers/hitcon.ts +++ b/front/src/ctfnote/parsers/hitcon.ts @@ -1,47 +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; +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;