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

Frontpage rework #256

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d027518
Change ctfcard layout
B-i-t-K May 4, 2024
a9d84b0
Add ctfsByDate and CtftimeCtf queries
B-i-t-K May 4, 2024
dd1469c
Added vcalendar to the dependencies and to boot
B-i-t-K May 4, 2024
aa086ec
Change index layout
B-i-t-K May 4, 2024
15a2178
fix formating issue
B-i-t-K May 4, 2024
6944cf8
Regenerate graphql schema
B-i-t-K May 4, 2024
3d8e8e9
remove margins from vc-bars
B-i-t-K May 6, 2024
34a743a
Created LinkChip and TimeChip.
B-i-t-K May 6, 2024
f4df250
remove borders from ctf-card and calendar
B-i-t-K May 6, 2024
ae31f32
make all the button square and the same size
B-i-t-K May 7, 2024
a3cb472
make timechip label optional
B-i-t-K May 7, 2024
1503c7a
Hide weight and ctftime url if not available
B-i-t-K May 7, 2024
0409bcb
add mini mode to CtfTimeLink
B-i-t-K May 7, 2024
a13076f
added archive page
B-i-t-K May 7, 2024
c06f5d0
fix ctftimeInput icon
B-i-t-K May 7, 2024
ea9fcc2
formating
B-i-t-K May 7, 2024
c148ccf
make calendar better for mobile
B-i-t-K May 7, 2024
ecd755a
make ctftime input button consistent with logo upload
B-i-t-K May 7, 2024
ab386d2
CTF card: fix end date
XeR May 31, 2024
919419b
Fix endtime, start time was displayed instead
B-i-t-K Aug 22, 2024
8e00117
added vueuse as a dependencie
B-i-t-K Aug 22, 2024
c55357d
Added infinite scroll
B-i-t-K Aug 22, 2024
8cf7041
Merge branch 'frontpage-rework' of https://github.com/TFNS/CTFNote in…
B-i-t-K Aug 22, 2024
df59b5d
Add sorting to the ctfarchive
B-i-t-K Aug 23, 2024
34c39ff
Fix typo
B-i-t-K Aug 23, 2024
49f20a1
Add a document.title for the index
B-i-t-K Aug 23, 2024
995b14b
Merge branch 'main' into frontpage-rework
JJ-8 Aug 25, 2024
b2d4fd5
Add missing ;
JJ-8 Aug 25, 2024
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
16 changes: 16 additions & 0 deletions api/migrations/54-ctf-by-date.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE FUNCTION ctfnote.ctfs_by_date(year int, month int)
RETURNS SETOF ctfnote.ctf
AS $$
SELECT
ctf.*
FROM
ctfnote.ctf
WHERE(start_time <= make_date(year, month, 1) + interval '1 month'
AND end_time >= make_date(year, month, 1))
ORDER BY start_time;
$$
LANGUAGE SQL
STABLE;

GRANT EXECUTE ON FUNCTION ctfnote.ctfs_by_date(int, int) TO user_guest;

53 changes: 47 additions & 6 deletions api/src/plugins/importCtf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@ interface CTFTimeResponse {
finish: string;
}

async function fetchFromCtftime(id: number): Promise<CTFTimeResponse> {
function fetchFromCtftime(id: number) {
const url = `https://ctftime.org/api/v1/events/${id}/`;
const response = await axios.get(url, {
headers: { "User-Agent": "CTFNote" }, // The default axios user-agent is blacklisted by ctftime :/
});
return response.data;
return axios
.get<CTFTimeResponse>(url, {
headers: { "User-Agent": "CTFNote" }, // The default axios user-agent is blacklisted by ctftime :/
})
.then((r) => ({
title: r.data.title,
weight: r.data.weight,
url: r.data.url,
logo: r.data.logo,
ctftimeUrl: r.data.ctftime_url,
description: r.data.description,
start: r.data.start,
finish: r.data.finish,
}))
.catch(() => null);
}

export default makeExtendSchemaPlugin((build) => {
Expand All @@ -34,11 +45,35 @@ export default makeExtendSchemaPlugin((build) => {
query: Query
}

type CtftimeCtf {
title: String!
weight: Float!
url: String!
logo: String!
ctftimeUrl: String!
description: String!
start: String!
finish: String!
}

extend type Mutation {
importCtf(input: ImportCtfInput): ImportCtfPayload
}

extend type Query {
ctftimeCtfById(id: Int!): CtftimeCtf
}
`,
resolvers: {
Query: {
async ctftimeCtfById(_query, { id }, { pgRole }) {
if (pgRole !== "user_manager" && pgRole !== "user_admin") {
throw new Error("Permission denied");
}

return fetchFromCtftime(id);
},
},
Mutation: {
importCtf: async (
_query,
Expand All @@ -47,6 +82,12 @@ export default makeExtendSchemaPlugin((build) => {
resolveInfo
) => {
const ctf = await fetchFromCtftime(ctftimeId);
if (!ctf) {
return {
data: null,
query: build.$$isQuery,
};
}
await savepointWrapper(pgClient, async () => {
const {
rows: [newCtf],
Expand All @@ -68,7 +109,7 @@ export default makeExtendSchemaPlugin((build) => {
ctf.weight,
ctf.url,
ctf.logo,
ctf.ctftime_url,
ctf.ctftimeUrl,
ctf.description,
ctf.start,
ctf.finish,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified front/.yarn/install-state.gz
Binary file not shown.
277 changes: 277 additions & 0 deletions front/graphql.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3774,6 +3774,145 @@
],
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "CtftimeCtf",
"description": null,
"fields": [
{
"name": "ctftimeUrl",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "description",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "finish",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "logo",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "start",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "title",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "url",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "weight",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Float",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "SCALAR",
"name": "Cursor",
Expand Down Expand Up @@ -9586,6 +9725,144 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "ctfsByDate",
"description": "Reads and enables pagination through a set of `Ctf`.",
"args": [
{
"name": "after",
"description": "Read all values in the set after (below) this cursor.",
"type": {
"kind": "SCALAR",
"name": "Cursor",
"ofType": null
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "before",
"description": "Read all values in the set before (above) this cursor.",
"type": {
"kind": "SCALAR",
"name": "Cursor",
"ofType": null
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "filter",
"description": "A filter to be used in determining which values should be returned by the collection.",
"type": {
"kind": "INPUT_OBJECT",
"name": "CtfFilter",
"ofType": null
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "first",
"description": "Only read the first `n` values of the set.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "last",
"description": "Only read the last `n` values of the set.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "month",
"description": null,
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "offset",
"description": "Skip the first `n` values from our `after` cursor, an alternative to cursor\nbased pagination. May not be used with `last`.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "year",
"description": null,
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"type": {
"kind": "OBJECT",
"name": "CtfsConnection",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "ctftimeCtfById",
"description": null,
"args": [
{
"name": "id",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"type": {
"kind": "OBJECT",
"name": "CtftimeCtf",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "guests",
"description": "Reads and enables pagination through a set of `Profile`.",
Expand Down
Loading