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 all 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;

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ALTER TABLE ctfnote.settings
ADD COLUMN "discord_integration_enabled" boolean NOT NULL DEFAULT FALSE;
GRANT SELECT ("discord_integration_enabled") ON ctfnote.settings TO user_anonymous;
REVOKE UPDATE ON ctfnote.settings FROM user_admin;
GRANT UPDATE (unique_id, registration_allowed, registration_password_allowed, registration_password, registration_default_role, style, ical_password) ON ctfnote.settings TO user_admin;
GRANT UPDATE ("discord_integration_enabled") ON ctfnote.settings TO user_postgraphile;
ALTER TABLE ctfnote.settings
ADD COLUMN "discord_integration_enabled" boolean NOT NULL DEFAULT FALSE;

GRANT SELECT ("discord_integration_enabled") ON ctfnote.settings TO user_anonymous;
REVOKE UPDATE ON ctfnote.settings FROM user_admin;
GRANT UPDATE (unique_id, registration_allowed, registration_password_allowed, registration_password, registration_default_role, style, ical_password) ON ctfnote.settings TO user_admin;
GRANT UPDATE ("discord_integration_enabled") ON ctfnote.settings TO user_postgraphile;

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 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 not shown.
Binary file not shown.
Binary file not shown.
Loading