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 ImaginaryCTF Parser #299

Closed
wants to merge 3 commits into from
Closed
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
54 changes: 54 additions & 0 deletions front/src/ctfnote/parsers/imaginary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { ParsedTask, Parser } from '.';
import { parseJsonStrict } from '../utils';

const ImaginaryParser: Parser = {
name: 'ImaginaryCTF parser',
hint: 'paste imaginary /api/challenges/released',
parse(s): ParsedTask[] {
const tasks: ParsedTask[] = [];
const data =
parseJsonStrict<
[{ title: string; category: string; description: string }]
>(s);
if (data == null) {
return [];
}

for (const challenge of data) {
if (!challenge.description || !challenge.title) {
continue;
}

tasks.push({
title: challenge.title,
tags: [challenge.category],
description: challenge.description,
});
}

return tasks;
},
isValid(s) {
const data = parseJsonStrict<
[
{
title: string;
category: string;
description: string;
release_date: string;
}
]
>(s);
if (data == null || data.length < 1) {
return false;
}
return (
data[0].title != null &&
data[0].category != null &&
data[0].description != null &&
data[0].release_date != null
);
},
};

export default ImaginaryParser;
2 changes: 2 additions & 0 deletions front/src/ctfnote/parsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import justCTFParser from './justctf';
import AngstromParser from './angstrom';
import CINIParser from './cini';
import HitconParser from './hitcon';
import ImaginaryParser from './imaginary';

export type ParsedTask = {
title: string;
Expand All @@ -30,4 +31,5 @@ export default [
AngstromParser,
CINIParser,
HitconParser,
ImaginaryParser,
];