Skip to content

Commit

Permalink
Merge pull request #64 from JJ-8/angstromparser-downstream
Browse files Browse the repository at this point in the history
Angstromparser downstream
  • Loading branch information
JJ-8 authored Sep 14, 2023
2 parents a097ed0 + 2399f4f commit 88bf3b6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
44 changes: 44 additions & 0 deletions front/src/ctfnote/parsers/angstrom.ts
Original file line number Diff line number Diff line change
@@ -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,
tags: [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;
2 changes: 2 additions & 0 deletions front/src/ctfnote/parsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,4 +27,5 @@ export default [
HTBParser,
PicoParser,
justCTFParser,
AngstromParser,
];

0 comments on commit 88bf3b6

Please sign in to comment.