Skip to content

Commit

Permalink
Update various event related things (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptlthg authored Jan 2, 2025
1 parent 0c51d5f commit 22c9c80
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/components/discord/event.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;`
: ''
);
</script>

<a
href="/event/{event?.id}"
class="items-centers relative flex w-full flex-1 flex-row justify-start gap-8 rounded-lg bg-primary-foreground bg-cover bg-center bg-no-repeat p-8 py-8 align-middle"
style={guild?.banner?.url ? `background-image: url(${guild.banner.url}); color: white;` : ''}
style={background || ''}
>
{#if guild?.banner}
<div
Expand Down
47 changes: 46 additions & 1 deletion src/lib/api/elite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,14 +566,17 @@ export const GetAdminEventMembers = async (token: string, guildId: string, event
},
});

export const GetEventMember = async (eventId: string, playerUuid: string) =>
export const GetEventMember = async (eventId: string, playerUuid: string, token?: string) =>
await GET('/event/{eventId}/member/{playerUuid}', {
params: {
path: {
eventId: eventId as unknown as number,
playerUuid,
},
},
headers: {
Authorization: token ? `Bearer ${token}` : undefined,
},
});

export const JoinEvent = async (eventId: string, accessToken: string, playerUuid?: string, profileId?: string) =>
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
SetEventBanner,
ClearEventBanner,
GetEventDefaults,
ForceAddEventMember,
PermDeleteEventMember,
} from '$lib/api/elite';
import type { components } from '$lib/api/api';

Expand Down Expand Up @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,62 @@
{/if}
{/await}
</div>
<div class="flex flex-col p-4">
<form
action="?/forceAddMember"
method="post"
class="flex flex-col gap-2"
use:enhance={() => {
pending = true;
return async ({ result, update }) => {
if (result) {
pending = false;
update();
}
};
}}
>
<input type="hidden" name="id" bind:value={data.event.id} />
<h4 class="text-lg">Force Add Member</h4>
<p class="max-w-lg text-sm">
This should be used very sparingly, and only with the consent of who is being added.
</p>

<div class="flex flex-row gap-2">
<Input name="uuid" placeholder="Player UUID" maxlength={32} required class="flex-1" />
<Input name="profile" placeholder="Profile UUID" maxlength={32} required class="flex-1" />
<Button type="submit" disabled={pending}>Add</Button>
</div>
</form>
</div>
<div class="flex flex-col p-4">
<form
action="?/permDeleteMember"
method="post"
class="flex flex-col gap-2"
use:enhance={() => {
pending = true;
return async ({ result, update }) => {
if (result) {
pending = false;
update();
}
};
}}
>
<input type="hidden" name="id" bind:value={data.event.id} />
<h4 class="text-lg">Delete Member Entry</h4>
<p class="max-w-lg text-sm">
This irreversibly deletes the database entry for a member. They will be able to join again. Only use
this if absolutely necessary.
</p>

<div class="flex flex-row gap-2">
<Input name="uuid" placeholder="Player UUID" maxlength={32} required class="flex-1" />
<Button type="submit" disabled={pending} variant="destructive">Delete</Button>
</div>
</form>
</div>
</main>

<Dialog.Root bind:open={banMemberModal}>
Expand Down
4 changes: 3 additions & 1 deletion src/routes/event/[event=slug]/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down
2 changes: 1 addition & 1 deletion src/routes/event/[event=slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);
</script>

Expand Down

0 comments on commit 22c9c80

Please sign in to comment.