From 22c9c80cee51d295aa12e45b50a8e5d3f17e85bd Mon Sep 17 00:00:00 2001 From: Kaeso <24925519+ptlthg@users.noreply.github.com> Date: Thu, 2 Jan 2025 15:39:34 -0600 Subject: [PATCH] Update various event related things (#350) --- src/components/discord/event.svelte | 10 ++- src/lib/api/elite.ts | 47 +++++++++++++- .../event/[eventId=snowflake]/+page.server.ts | 63 +++++++++++++++++++ .../event/[eventId=snowflake]/+page.svelte | 56 +++++++++++++++++ .../event/[event=slug]/+layout.server.ts | 4 +- src/routes/event/[event=slug]/+page.svelte | 2 +- 6 files changed, 178 insertions(+), 4 deletions(-) diff --git a/src/components/discord/event.svelte b/src/components/discord/event.svelte index c612a5a6..f419b454 100644 --- a/src/components/discord/event.svelte +++ b/src/components/discord/event.svelte @@ -12,12 +12,20 @@ let start = $derived(new Date(+(event.startTime ?? 0) * 1000)); let end = $derived(new Date(+(event.endTime ?? 0) * 1000)); + + let background = $derived( + event.banner?.url + ? `background-image: url(${event.banner.url}); color: white;` + : guild?.banner?.url + ? `background-image: url(${guild.banner.url}); color: white;` + : '' + ); {#if guild?.banner}
+export const GetEventMember = async (eventId: string, playerUuid: string, token?: string) => await GET('/event/{eventId}/member/{playerUuid}', { params: { path: { @@ -574,6 +574,9 @@ export const GetEventMember = async (eventId: string, playerUuid: string) => playerUuid, }, }, + headers: { + Authorization: token ? `Bearer ${token}` : undefined, + }, }); export const JoinEvent = async (eventId: string, accessToken: string, playerUuid?: string, profileId?: string) => @@ -723,6 +726,48 @@ export const UnbanEventMember = async (accessToken: string, guildId: string, eve }, }); +export const ForceAddEventMember = async ( + accessToken: string, + guildId: string, + eventId: string, + playerUuid: string, + profileUuid: string +) => + await POST('/guild/{guildId}/events/{eventId}/members/{playerUuid}', { + params: { + path: { + guildId: guildId as unknown as number, + eventId: eventId as unknown as number, + playerUuid, + }, + query: { + profileId: profileUuid, + }, + }, + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }); + +export const PermDeleteEventMember = async ( + accessToken: string, + guildId: string, + eventId: string, + playerUuid: string +) => + await DELETE('/guild/{guildId}/events/{eventId}/members/{playerUuid}', { + params: { + path: { + guildId: guildId as unknown as number, + eventId: eventId as unknown as number, + playerUuid, + }, + }, + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }); + export const GetYearlyContestRecords = async (year: number) => await GET('/contests/records/{year}', { params: { diff --git a/src/routes/(auth)/guild/[id=snowflake]/event/[eventId=snowflake]/+page.server.ts b/src/routes/(auth)/guild/[id=snowflake]/event/[eventId=snowflake]/+page.server.ts index 4dadd9b3..3423d865 100644 --- a/src/routes/(auth)/guild/[id=snowflake]/event/[eventId=snowflake]/+page.server.ts +++ b/src/routes/(auth)/guild/[id=snowflake]/event/[eventId=snowflake]/+page.server.ts @@ -11,6 +11,8 @@ import { SetEventBanner, ClearEventBanner, GetEventDefaults, + ForceAddEventMember, + PermDeleteEventMember, } from '$lib/api/elite'; import type { components } from '$lib/api/api'; @@ -295,6 +297,67 @@ export const actions: Actions = { return fail(response.status, { error: msg }); } + return { + success: true, + }; + }, + forceAddMember: async ({ locals, params, request }) => { + const guildId = params.id; + const { access_token: token } = locals; + + if (!locals.session || !guildId || !token) { + throw error(401, 'Unauthorized'); + } + + const data = await request.formData(); + + const eventId = data.get('id') as string; + if (!eventId) throw error(400, 'Missing required field: id'); + + const uuid = data.get('uuid') as string; + if (!uuid) return fail(400, { error: 'Missing required field: uuid' }); + + const profile = data.get('profile') as string; + if (!profile) return fail(400, { error: 'Missing required field: profile' }); + + const { response, error: e } = await ForceAddEventMember(token, guildId, eventId, uuid, profile).catch((e) => { + console.log(e); + throw error(500, 'Internal Server Error'); + }); + + if (!response.ok || e) { + return fail(response.status, { error: e }); + } + + return { + success: true, + }; + }, + permDeleteMember: async ({ locals, params, request }) => { + const guildId = params.id; + const { access_token: token } = locals; + + if (!locals.session || !guildId || !token) { + throw error(401, 'Unauthorized'); + } + + const data = await request.formData(); + + const eventId = data.get('id') as string; + if (!eventId) throw error(400, 'Missing required field: id'); + + const uuid = data.get('uuid') as string; + if (!uuid) return fail(400, { error: 'Missing required field: uuid' }); + + const { response, error: e } = await PermDeleteEventMember(token, guildId, eventId, uuid).catch((e) => { + console.log(e); + throw error(500, 'Internal Server Error'); + }); + + if (!response.ok || e) { + return fail(response.status, { error: e }); + } + return { success: true, }; diff --git a/src/routes/(auth)/guild/[id=snowflake]/event/[eventId=snowflake]/+page.svelte b/src/routes/(auth)/guild/[id=snowflake]/event/[eventId=snowflake]/+page.svelte index 8da0cf84..9d8a6c41 100644 --- a/src/routes/(auth)/guild/[id=snowflake]/event/[eventId=snowflake]/+page.svelte +++ b/src/routes/(auth)/guild/[id=snowflake]/event/[eventId=snowflake]/+page.svelte @@ -435,6 +435,62 @@ {/if} {/await}
+
+
{ + pending = true; + return async ({ result, update }) => { + if (result) { + pending = false; + update(); + } + }; + }} + > + +

Force Add Member

+

+ This should be used very sparingly, and only with the consent of who is being added. +

+ +
+ + + +
+
+
+
+
{ + pending = true; + return async ({ result, update }) => { + if (result) { + pending = false; + update(); + } + }; + }} + > + +

Delete Member Entry

+

+ This irreversibly deletes the database entry for a member. They will be able to join again. Only use + this if absolutely necessary. +

+ +
+ + +
+
+
diff --git a/src/routes/event/[event=slug]/+layout.server.ts b/src/routes/event/[event=slug]/+layout.server.ts index 45c333fa..64d5114a 100644 --- a/src/routes/event/[event=slug]/+layout.server.ts +++ b/src/routes/event/[event=slug]/+layout.server.ts @@ -23,7 +23,9 @@ export const load = (async ({ params, url, locals }) => { const { data: guild } = await GetPublicGuild(eventData.guildId).catch(() => ({ data: undefined })); const { data: self } = locals.session?.uuid - ? await GetEventMember(eventData.id, locals.session?.uuid).catch(() => ({ data: undefined })) + ? await GetEventMember(eventData.id, locals.session?.uuid, locals.access_token).catch(() => ({ + data: undefined, + })) : { data: undefined }; const { data: members } = await GetEventMembers(eventData.id).catch(() => ({ data: undefined })); diff --git a/src/routes/event/[event=slug]/+page.svelte b/src/routes/event/[event=slug]/+page.svelte index 72de9e16..25b214b5 100644 --- a/src/routes/event/[event=slug]/+page.svelte +++ b/src/routes/event/[event=slug]/+page.svelte @@ -60,7 +60,7 @@ ); let description = $derived( - `View the ${running ? 'Event happening' : 'past Event'} in ${data.guild?.name}!\n\n${topList}` + `View the ${running ? 'Event happening' : 'Event'} in ${data.guild?.name}!\n\n${topList}` );