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

Angstromparser downstream #64

Merged
merged 2 commits into from
Sep 14, 2023
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
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,
];
Loading