DISABLE SSR AND TRANSITION TO SPA
All checks were successful
Build Formula11 Docker Image / pocketbase-docker (push) Successful in 43s
All checks were successful
Build Formula11 Docker Image / pocketbase-docker (push) Successful in 43s
This commit is contained in:
@ -1,55 +0,0 @@
|
||||
import {
|
||||
form_data_clean,
|
||||
form_data_ensure_keys,
|
||||
form_data_get_and_remove_id,
|
||||
form_data_remove,
|
||||
} from "$lib/form";
|
||||
import type { Driver, Graphic, Race, RaceResult } from "$lib/schema";
|
||||
import type { Actions, PageServerLoad } from "./$types";
|
||||
|
||||
export const actions = {
|
||||
create_raceresult: async ({ request, locals }) => {
|
||||
if (!locals.admin) return { unauthorized: true };
|
||||
|
||||
const data: FormData = form_data_clean(await request.formData());
|
||||
form_data_ensure_keys(data, ["race", "pxxs"]);
|
||||
form_data_remove(data, ["pxxs_codes", "dnfs_codes"]);
|
||||
|
||||
await locals.pb.collection("raceresults").create(data);
|
||||
},
|
||||
|
||||
update_raceresult: async ({ request, locals }) => {
|
||||
if (!locals.admin) return { unauthorized: true };
|
||||
|
||||
const data: FormData = form_data_clean(await request.formData());
|
||||
form_data_remove(data, ["pxxs_codes", "dnfs_codes"]);
|
||||
const id: string = form_data_get_and_remove_id(data);
|
||||
|
||||
console.dir(data, { depth: null });
|
||||
|
||||
await locals.pb.collection("raceresults").update(id, data);
|
||||
},
|
||||
|
||||
delete_raceresult: async ({ request, locals }) => {
|
||||
if (!locals.admin) return { unauthorized: true };
|
||||
|
||||
const data: FormData = form_data_clean(await request.formData());
|
||||
form_data_remove(data, ["pxxs_codes", "dnfs_codes"]);
|
||||
const id: string = form_data_get_and_remove_id(data);
|
||||
|
||||
await locals.pb.collection("raceresults").delete(id);
|
||||
},
|
||||
} as Actions;
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch, locals }) => {
|
||||
// TODO: Duplicated code from racepicks/+page.server.ts
|
||||
const fetch_raceresults = async (): Promise<RaceResult[]> => {
|
||||
const raceresults: RaceResult[] = await locals.pb.collection("raceresultsdesc").getFullList();
|
||||
|
||||
return raceresults;
|
||||
};
|
||||
|
||||
return {
|
||||
results: await fetch_raceresults(),
|
||||
};
|
||||
};
|
||||
18
src/routes/data/raceresults/+page.ts
Normal file
18
src/routes/data/raceresults/+page.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import type { RaceResult } from "$lib/schema";
|
||||
import type { PageLoad } from "../../$types";
|
||||
|
||||
export const load: PageLoad = async ({ fetch }) => {
|
||||
// TODO: Duplicated code from racepicks/+page.server.ts
|
||||
const fetch_raceresults = async (): Promise<RaceResult[]> => {
|
||||
const raceresults: RaceResult[] = await pb
|
||||
.collection("raceresultsdesc")
|
||||
.getFullList({ fetch: fetch });
|
||||
|
||||
return raceresults;
|
||||
};
|
||||
|
||||
return {
|
||||
results: await fetch_raceresults(),
|
||||
};
|
||||
};
|
||||
@ -1,59 +0,0 @@
|
||||
import { DRIVER_HEADSHOT_HEIGHT, DRIVER_HEADSHOT_WIDTH } from "$lib/config";
|
||||
import { form_data_clean, form_data_ensure_keys, form_data_get_and_remove_id } from "$lib/form";
|
||||
import { image_to_avif } from "$lib/server/image";
|
||||
import type { Actions } from "@sveltejs/kit";
|
||||
|
||||
export const actions = {
|
||||
create_driver: async ({ request, locals }) => {
|
||||
if (!locals.admin) return { unauthorized: true };
|
||||
|
||||
const data: FormData = form_data_clean(await request.formData());
|
||||
form_data_ensure_keys(data, ["firstname", "lastname", "code", "team", "headshot"]);
|
||||
|
||||
// The toggle switch will report "on" or nothing
|
||||
data.set("active", data.has("active") ? "true" : "false");
|
||||
|
||||
// Compress headshot
|
||||
const headshot_avif: Blob = await image_to_avif(
|
||||
await (data.get("headshot") as File).arrayBuffer(),
|
||||
DRIVER_HEADSHOT_WIDTH,
|
||||
DRIVER_HEADSHOT_HEIGHT,
|
||||
);
|
||||
|
||||
data.set("headshot", headshot_avif);
|
||||
|
||||
await locals.pb.collection("drivers").create(data);
|
||||
},
|
||||
|
||||
update_driver: async ({ request, locals }) => {
|
||||
if (!locals.admin) return { unauthorized: true };
|
||||
|
||||
const data: FormData = form_data_clean(await request.formData());
|
||||
const id: string = form_data_get_and_remove_id(data);
|
||||
|
||||
// The toggle switch will report "on" or nothing
|
||||
data.set("active", data.has("active") ? "true" : "false");
|
||||
|
||||
if (data.has("headshot")) {
|
||||
// Compress headshot
|
||||
const headshot_avif: Blob = await image_to_avif(
|
||||
await (data.get("headshot") as File).arrayBuffer(),
|
||||
DRIVER_HEADSHOT_WIDTH,
|
||||
DRIVER_HEADSHOT_HEIGHT,
|
||||
);
|
||||
|
||||
data.set("headshot", headshot_avif);
|
||||
}
|
||||
|
||||
await locals.pb.collection("drivers").update(id, data);
|
||||
},
|
||||
|
||||
delete_driver: async ({ request, locals }) => {
|
||||
if (!locals.admin) return { unauthorized: true };
|
||||
|
||||
const data: FormData = form_data_clean(await request.formData());
|
||||
const id: string = form_data_get_and_remove_id(data);
|
||||
|
||||
await locals.pb.collection("drivers").delete(id);
|
||||
},
|
||||
} satisfies Actions;
|
||||
@ -1,64 +0,0 @@
|
||||
import { RACE_PICTOGRAM_HEIGHT, RACE_PICTOGRAM_WIDTH } from "$lib/config";
|
||||
import {
|
||||
form_data_clean,
|
||||
form_data_ensure_keys,
|
||||
form_data_fix_dates,
|
||||
form_data_get_and_remove_id,
|
||||
} from "$lib/form";
|
||||
import { image_to_avif } from "$lib/server/image";
|
||||
import type { Actions } from "@sveltejs/kit";
|
||||
|
||||
export const actions = {
|
||||
create_race: async ({ request, locals }) => {
|
||||
if (!locals.admin) return { unauthorized: true };
|
||||
|
||||
const data: FormData = form_data_clean(await request.formData());
|
||||
form_data_ensure_keys(data, ["name", "step", "pictogram", "pxx", "qualidate", "racedate"]);
|
||||
form_data_fix_dates(data, ["sprintqualidate", "sprintdate", "qualidate", "racedate"]);
|
||||
|
||||
// Compress pictogram
|
||||
const pictogram_avif: Blob = await image_to_avif(
|
||||
await (data.get("pictogram") as File).arrayBuffer(),
|
||||
RACE_PICTOGRAM_WIDTH,
|
||||
RACE_PICTOGRAM_HEIGHT,
|
||||
);
|
||||
|
||||
data.set("pictogram", pictogram_avif);
|
||||
|
||||
await locals.pb.collection("races").create(data);
|
||||
},
|
||||
|
||||
update_race: async ({ request, locals }) => {
|
||||
if (!locals.admin) return { unauthorized: true };
|
||||
|
||||
// Do not remove empty sprint dates so they can be cleared by updating the record
|
||||
const data: FormData = form_data_clean(await request.formData(), [
|
||||
"sprintqualidate",
|
||||
"sprintdate",
|
||||
]);
|
||||
form_data_fix_dates(data, ["sprintqualidate", "sprintdate", "qualidate", "racedate"]);
|
||||
const id: string = form_data_get_and_remove_id(data);
|
||||
|
||||
if (data.has("pictogram")) {
|
||||
// Compress pictogram
|
||||
const pictogram_avif: Blob = await image_to_avif(
|
||||
await (data.get("pictogram") as File).arrayBuffer(),
|
||||
RACE_PICTOGRAM_WIDTH,
|
||||
RACE_PICTOGRAM_HEIGHT,
|
||||
);
|
||||
|
||||
data.set("pictogram", pictogram_avif);
|
||||
}
|
||||
|
||||
await locals.pb.collection("races").update(id, data);
|
||||
},
|
||||
|
||||
delete_race: async ({ request, locals }) => {
|
||||
if (!locals.admin) return { unauthorized: true };
|
||||
|
||||
const data: FormData = form_data_clean(await request.formData());
|
||||
const id: string = form_data_get_and_remove_id(data);
|
||||
|
||||
await locals.pb.collection("races").delete(id);
|
||||
},
|
||||
} satisfies Actions;
|
||||
@ -26,6 +26,7 @@
|
||||
modalStore.trigger(modalSettings);
|
||||
};
|
||||
|
||||
// TODO: Displayed dates differ from actual dates by 1 hour
|
||||
const races_columns: TableColumn[] = $derived([
|
||||
{
|
||||
data_value_name: "name",
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
import { form_data_clean, form_data_ensure_keys, form_data_get_and_remove_id } from "$lib/form";
|
||||
import type { Actions } from "@sveltejs/kit";
|
||||
|
||||
export const actions = {
|
||||
create_substitution: async ({ request, locals }) => {
|
||||
if (!locals.admin) return { unauthorized: true };
|
||||
|
||||
const data: FormData = form_data_clean(await request.formData());
|
||||
form_data_ensure_keys(data, ["substitute", "for", "race"]);
|
||||
|
||||
await locals.pb.collection("substitutions").create(data);
|
||||
},
|
||||
|
||||
update_substitution: async ({ request, locals }) => {
|
||||
if (!locals.admin) return { unauthorized: true };
|
||||
|
||||
const data: FormData = form_data_clean(await request.formData());
|
||||
const id: string = form_data_get_and_remove_id(data);
|
||||
|
||||
await locals.pb.collection("substitutions").update(id, data);
|
||||
},
|
||||
|
||||
delete_substitution: async ({ request, locals }) => {
|
||||
if (!locals.admin) return { unauthorized: true };
|
||||
|
||||
const data: FormData = form_data_clean(await request.formData());
|
||||
const id: string = form_data_get_and_remove_id(data);
|
||||
|
||||
await locals.pb.collection("substitutions").delete(id);
|
||||
},
|
||||
} satisfies Actions;
|
||||
@ -1,74 +0,0 @@
|
||||
import type { Actions } from "./$types";
|
||||
import { form_data_clean, form_data_ensure_keys, form_data_get_and_remove_id } from "$lib/form";
|
||||
import { image_to_avif } from "$lib/server/image";
|
||||
import {
|
||||
TEAM_BANNER_HEIGHT,
|
||||
TEAM_BANNER_WIDTH,
|
||||
TEAM_LOGO_HEIGHT,
|
||||
TEAM_LOGO_WIDTH,
|
||||
} from "$lib/config";
|
||||
|
||||
export const actions = {
|
||||
create_team: async ({ request, locals }) => {
|
||||
if (!locals.admin) return { unauthorized: true };
|
||||
|
||||
const data: FormData = form_data_clean(await request.formData());
|
||||
form_data_ensure_keys(data, ["name", "banner", "logo", "color"]);
|
||||
|
||||
// Compress banner
|
||||
const banner_avif: Blob = await image_to_avif(
|
||||
await (data.get("banner") as File).arrayBuffer(),
|
||||
TEAM_BANNER_WIDTH,
|
||||
TEAM_BANNER_HEIGHT,
|
||||
);
|
||||
data.set("banner", banner_avif);
|
||||
|
||||
// Compress logo
|
||||
const logo_avif: Blob = await image_to_avif(
|
||||
await (data.get("logo") as File).arrayBuffer(),
|
||||
TEAM_LOGO_WIDTH,
|
||||
TEAM_LOGO_HEIGHT,
|
||||
);
|
||||
data.set("logo", logo_avif);
|
||||
|
||||
await locals.pb.collection("teams").create(data);
|
||||
},
|
||||
|
||||
update_team: async ({ request, locals }) => {
|
||||
if (!locals.admin) return { unauthorized: true };
|
||||
|
||||
const data: FormData = form_data_clean(await request.formData());
|
||||
const id: string = form_data_get_and_remove_id(data);
|
||||
|
||||
if (data.has("banner")) {
|
||||
// Compress banner
|
||||
const banner_avif: Blob = await image_to_avif(
|
||||
await (data.get("banner") as File).arrayBuffer(),
|
||||
TEAM_BANNER_WIDTH,
|
||||
TEAM_BANNER_HEIGHT,
|
||||
);
|
||||
data.set("banner", banner_avif);
|
||||
}
|
||||
|
||||
if (data.has("logo")) {
|
||||
// Compress logo
|
||||
const logo_avif: Blob = await image_to_avif(
|
||||
await (data.get("logo") as File).arrayBuffer(),
|
||||
TEAM_LOGO_WIDTH,
|
||||
TEAM_LOGO_HEIGHT,
|
||||
);
|
||||
data.set("logo", logo_avif);
|
||||
}
|
||||
|
||||
await locals.pb.collection("teams").update(id, data);
|
||||
},
|
||||
|
||||
delete_team: async ({ request, locals }) => {
|
||||
if (!locals.admin) return { unauthorized: true };
|
||||
|
||||
const data: FormData = form_data_clean(await request.formData());
|
||||
const id: string = form_data_get_and_remove_id(data);
|
||||
|
||||
await locals.pb.collection("teams").delete(id);
|
||||
},
|
||||
} satisfies Actions;
|
||||
@ -1,20 +0,0 @@
|
||||
import type { Graphic, User } from "$lib/schema";
|
||||
import type { PageServerLoad } from "./$types";
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch, locals }) => {
|
||||
const fetch_users = async (): Promise<User[]> => {
|
||||
const users: User[] = await locals.pb
|
||||
.collection("users")
|
||||
.getFullList({ fetch: fetch, sort: "+username" });
|
||||
|
||||
users.map((user: User) => {
|
||||
user.avatar_url = locals.pb.files.getURL(user, user.avatar);
|
||||
});
|
||||
|
||||
return users;
|
||||
};
|
||||
|
||||
return {
|
||||
users: await fetch_users(),
|
||||
};
|
||||
};
|
||||
21
src/routes/data/users/+page.ts
Normal file
21
src/routes/data/users/+page.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import type { User } from "$lib/schema";
|
||||
import type { PageLoad } from "../../$types";
|
||||
|
||||
export const load: PageLoad = async ({ fetch }) => {
|
||||
const fetch_users = async (): Promise<User[]> => {
|
||||
const users: User[] = await pb
|
||||
.collection("users")
|
||||
.getFullList({ fetch: fetch, sort: "+username" });
|
||||
|
||||
users.map((user: User) => {
|
||||
user.avatar_url = pb.files.getURL(user, user.avatar);
|
||||
});
|
||||
|
||||
return users;
|
||||
};
|
||||
|
||||
return {
|
||||
users: await fetch_users(),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user