[web] Upgrade major deps (Sveltekit 2)

This commit is contained in:
orosmatthew 2023-12-19 16:58:34 -05:00
parent 48f97a8ffb
commit a19950a094
17 changed files with 476 additions and 284 deletions

626
web/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,8 @@
"format": "prettier --plugin prettier-plugin-svelte --write ."
},
"devDependencies": {
"@sveltejs/kit": "^1.27.6",
"@sveltejs/kit": "^2.0.4",
"@sveltejs/vite-plugin-svelte": "^3.0.1",
"@types/bcrypt": "^5.0.2",
"@types/bootstrap": "^5.2.10",
"@types/diff": "^5.0.9",
@ -30,12 +31,12 @@
"svelte-check": "^3.6.2",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"vite": "^4.5.1"
"vite": "^5.0.10"
},
"type": "module",
"dependencies": {
"@prisma/client": "^5.7.1",
"@sveltejs/adapter-node": "^1.3.1",
"@sveltejs/adapter-node": "^2.0.1",
"@types/fs-extra": "^11.0.4",
"bcrypt": "^5.1.1",
"bootstrap": "^5.3.2",

View File

@ -38,13 +38,13 @@ export const handle = (async ({ event, resolve }) => {
if (event.url.pathname.startsWith('/login')) {
if ((await isSessionValid(event.cookies)) === true) {
throw redirect(302, '/admin');
redirect(302, '/admin');
}
}
if (event.url.pathname.startsWith('/admin')) {
if ((await isSessionValid(event.cookies)) !== true) {
logout(event.cookies);
throw redirect(302, '/login');
redirect(302, '/login');
}
}
const res = await resolve(event, {

View File

@ -30,7 +30,7 @@ export async function logout(cookies: Cookies): Promise<boolean> {
if (sessionCookie === undefined) {
return false;
}
cookies.delete('session');
cookies.delete('session', { path: '/' });
try {
await db.session.delete({ where: { token: sessionCookie } });
} catch {
@ -57,6 +57,7 @@ export async function attemptLogin(
const session = await db.session.create({ data: { userId: user.id } });
cookies.set('session', session.token, {
// secure: process.env.NODE_ENV === 'development' ? false : true,
path: '/',
secure: false,
httpOnly: true,
sameSite: 'strict',
@ -85,6 +86,6 @@ export async function isSessionValid(cookies: Cookies): Promise<boolean> {
export async function redirectIfSessionInvalid(url: string, cookies: Cookies): Promise<void> {
if (!(await isSessionValid(cookies))) {
throw redirect(302, url);
redirect(302, url);
}
}

View File

@ -8,14 +8,14 @@ import { createRepos } from '$lib/server/repos';
export const load = (async ({ params }) => {
const contestId = parseInt(params.contestId);
if (isNaN(contestId)) {
throw error(400, 'Invalid request');
error(400, 'Invalid request');
}
const contest = await db.contest.findUnique({
where: { id: contestId },
include: { problems: true, teams: true, activeTeams: true }
});
if (!contest) {
throw redirect(302, '/admin/contests');
redirect(302, '/admin/contests');
}
return {
name: contest.name,
@ -39,7 +39,7 @@ export const actions = {
} catch {
return { success: false };
}
throw redirect(302, '/admin/contests');
redirect(302, '/admin/contests');
},
start: async ({ params }) => {
if (!params.contestId) {

View File

@ -4,11 +4,11 @@ import { db } from '$lib/server/prisma';
export const load = (async ({ params }) => {
if (!params.contestId) {
throw redirect(302, '/admin/contests');
redirect(302, '/admin/contests');
}
const contestId = parseInt(params.contestId);
if (isNaN(contestId)) {
throw redirect(302, '/admin/contests');
redirect(302, '/admin/contests');
}
const contest = await db.contest.findUnique({
@ -16,7 +16,7 @@ export const load = (async ({ params }) => {
include: { teams: true }
});
if (!contest) {
throw redirect(302, '/admin/contests');
redirect(302, '/admin/contests');
}
return {

View File

@ -6,15 +6,15 @@ import { SubmissionState, SubmissionStateReason } from '@prisma/client';
export const load = (async ({ params }) => {
const submissionId = parseInt(params.submissionId);
if (isNaN(submissionId)) {
throw error(400, 'Invalid request');
error(400, 'Invalid request');
}
const submission = await db.submission.findUnique({ where: { id: submissionId } });
if (!submission) {
throw redirect(302, '/admin/reviews');
redirect(302, '/admin/reviews');
}
const problem = await db.problem.findUnique({ where: { id: submission.problemId } });
if (!problem) {
throw error(500, 'Invalid problem');
error(500, 'Invalid problem');
}
return { diff: submission.diff, submissionId: submission.id, output: submission.actualOutput };
@ -38,7 +38,7 @@ export const actions = {
where: { id: submissionId },
data: {
state: correctBool ? SubmissionState.Correct : SubmissionState.Incorrect,
stateReason : correctBool ? SubmissionStateReason.IncorrectOverriddenAsCorrect : null,
stateReason: correctBool ? SubmissionStateReason.IncorrectOverriddenAsCorrect : null,
message: message ? message.toString() : '',
gradedAt: gradedTime
}

View File

@ -5,11 +5,11 @@ import type { Actions, PageServerLoad } from './$types';
export const load = (async ({ params }) => {
const problemId = parseInt(params.problemId);
if (isNaN(problemId)) {
throw error(400, 'Invalid request');
error(400, 'Invalid request');
}
const query = await db.problem.findUnique({ where: { id: problemId } });
if (!query) {
throw redirect(302, '/admin/problems');
redirect(302, '/admin/problems');
}
return { problemData: query };
}) satisfies PageServerLoad;
@ -18,7 +18,7 @@ export const actions = {
edit: async ({ params, request }) => {
const problemId = parseInt(params.problemId);
if (isNaN(problemId)) {
throw error(400, 'Invalid problem');
error(400, 'Invalid problem');
}
const data = await request.formData();
const name = data.get('name');

View File

@ -5,7 +5,7 @@ import { db } from '$lib/server/prisma';
export const DELETE = (async ({ params }) => {
const problemId = parseInt(params.problemId);
if (isNaN(problemId)) {
throw error(400, 'Invalid problem');
error(400, 'Invalid problem');
}
try {
await db.problem.delete({ where: { id: problemId } });

View File

@ -5,19 +5,19 @@ import { db } from '$lib/server/prisma';
export const load = (async ({ params }) => {
const submissionId = parseInt(params.submissionId);
if (isNaN(submissionId)) {
throw error(400, 'Invalid submission');
error(400, 'Invalid submission');
}
const submission = await db.submission.findUnique({ where: { id: submissionId } });
if (!submission) {
throw redirect(302, '/admin/submissions');
redirect(302, '/admin/submissions');
}
const team = await db.team.findUnique({ where: { id: submission.teamId } });
if (!team) {
throw error(500, 'Invalid team');
error(500, 'Invalid team');
}
const problem = await db.problem.findUnique({ where: { id: submission.problemId } });
if (!problem) {
throw error(500, 'Invalid problem');
error(500, 'Invalid problem');
}
return {
id: submission.id,
@ -42,6 +42,6 @@ export const actions = {
} catch {
return { success: false };
}
throw redirect(302, '/admin/submissions');
redirect(302, '/admin/submissions');
}
} satisfies Actions;

View File

@ -129,10 +129,14 @@
</div>
{:else if data.state == 'Incorrect' && data.stateReason == 'BuildError'}
<h3 style="text-align:center">Build Output</h3>
<textarea use:stretchTextarea class="code mb-3 form-control" disabled>{data.stateReasonDetails}</textarea>
<textarea use:stretchTextarea class="code mb-3 form-control" disabled
>{data.stateReasonDetails}</textarea
>
{:else if data.state == 'Incorrect' && data.stateReason == 'TimeLimitExceeded'}
<h3 style="text-align:center">Details</h3>
<textarea use:stretchTextarea class="code mb-3 form-control" disabled>{data.stateReasonDetails}</textarea>
<textarea use:stretchTextarea class="code mb-3 form-control" disabled
>{data.stateReasonDetails}</textarea
>
{:else}
<h3 style="text-align:center">Output</h3>
<textarea use:stretchTextarea class="code mb-3 form-control" disabled>{data.output}</textarea>

View File

@ -34,7 +34,7 @@ export const GET = (async () => {
}
}) satisfies RequestHandler;
const RunResultKind = z.enum(["CompileFailed", "TimeLimitExceeded", "Completed", "SandboxError"]);
const RunResultKind = z.enum(['CompileFailed', 'TimeLimitExceeded', 'Completed', 'SandboxError']);
export type RunResultKind = z.infer<typeof RunResultKind>;
const RunResult = z
@ -58,8 +58,10 @@ export const POST = (async ({ request }) => {
const requestJson = await request.json();
const data = submissionPostData.safeParse(requestJson);
if (!data.success) {
console.log("Error: POST to Submission API failed to parse given object: " + JSON.stringify(requestJson));
throw error(400);
console.log(
'Error: POST to Submission API failed to parse given object: ' + JSON.stringify(requestJson)
);
error(400);
}
const submission = await db.submission.findUnique({
@ -68,12 +70,16 @@ export const POST = (async ({ request }) => {
});
if (!submission) {
console.log("Error: POST to Submission API for unknown submissionId: " + data.data.submissionId);
console.log(
'Error: POST to Submission API for unknown submissionId: ' + data.data.submissionId
);
return json({ success: false });
}
if (submission.state !== SubmissionState.Queued) {
console.log("Error: POST to Submission API for already judged submissionId: " + data.data.submissionId);
console.log(
'Error: POST to Submission API for already judged submissionId: ' + data.data.submissionId
);
return json({ success: false });
}
@ -82,8 +88,13 @@ export const POST = (async ({ request }) => {
if (data.data.result.output!.trimEnd() === submission.problem.realOutput.trimEnd()) {
await db.submission.update({
where: { id: data.data.submissionId },
data: { state: SubmissionState.Correct, gradedAt: new Date(), actualOutput: data.data.result.output,
stateReason: null, stateReasonDetails: null }
data: {
state: SubmissionState.Correct,
gradedAt: new Date(),
actualOutput: data.data.result.output,
stateReason: null,
stateReasonDetails: null
}
});
return json({ success: true });
} else {
@ -95,8 +106,13 @@ export const POST = (async ({ request }) => {
);
await db.submission.update({
where: { id: data.data.submissionId },
data: { state: SubmissionState.InReview, diff: diff, actualOutput: data.data.result.output,
stateReason: null, stateReasonDetails: null }
data: {
state: SubmissionState.InReview,
diff: diff,
actualOutput: data.data.result.output,
stateReason: null,
stateReasonDetails: null
}
});
return json({ success: true });
}
@ -105,16 +121,25 @@ export const POST = (async ({ request }) => {
console.log('compile failed...');
await db.submission.update({
where: { id: data.data.submissionId },
data: { state: SubmissionState.Incorrect, gradedAt: new Date(),
stateReason: SubmissionStateReason.BuildError, stateReasonDetails: data.data.result.resultKindReason }
data: {
state: SubmissionState.Incorrect,
gradedAt: new Date(),
stateReason: SubmissionStateReason.BuildError,
stateReasonDetails: data.data.result.resultKindReason
}
});
return json({ success: true });
case 'TimeLimitExceeded':
await db.submission.update({
where: { id: data.data.submissionId },
data: { state: SubmissionState.Incorrect, gradedAt: new Date(), actualOutput: data.data.result.output,
stateReason: SubmissionStateReason.TimeLimitExceeded, stateReasonDetails: data.data.result.resultKindReason }
data: {
state: SubmissionState.Incorrect,
gradedAt: new Date(),
actualOutput: data.data.result.output,
stateReason: SubmissionStateReason.TimeLimitExceeded,
stateReasonDetails: data.data.result.resultKindReason
}
});
return json({ success: true });
@ -122,7 +147,10 @@ export const POST = (async ({ request }) => {
// TODO: Raise to admins somehow. For now, just mark stateReason so it *could* be observed
await db.submission.update({
where: { id: data.data.submissionId },
data: { stateReason: SubmissionStateReason.SandboxError, stateReasonDetails: data.data.result.resultKindReason }
data: {
stateReason: SubmissionStateReason.SandboxError,
stateReasonDetails: data.data.result.resultKindReason
}
});
return json({ success: true });
}

View File

@ -19,11 +19,11 @@ export const POST = (async ({ params, request }) => {
}
});
if (!activeTeam) {
throw error(400);
error(400);
}
const data = submitPostData.safeParse(await request.json());
if (!data.success) {
throw error(400);
error(400);
}
if (
@ -31,7 +31,7 @@ export const POST = (async ({ params, request }) => {
return problem.id == data.data.problemId;
})
) {
throw error(400);
error(400);
}
// Make sure no submission is currently marked correct

View File

@ -14,7 +14,7 @@ const loginPostData = z
export const POST = (async ({ request }) => {
const data = loginPostData.safeParse(await request.json());
if (!data.success) {
throw error(400);
error(400);
}
const team = await db.team.findUnique({
where: { name: data.data.teamname },

View File

@ -12,7 +12,7 @@ const logoutPostData = z
export const POST = (async ({ request }) => {
const data = logoutPostData.safeParse(await request.json());
if (!data.success) {
throw error(400);
error(400);
}
await db.activeTeam.update({
where: { sessionToken: data.data.token },

View File

@ -1,5 +1,5 @@
import adapter from '@sveltejs/adapter-node';
import { vitePreprocess } from '@sveltejs/kit/vite';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */
const config = {