From 4f52c71c7a9bfa6f0fbe7df4f20d7c8cf07087d2 Mon Sep 17 00:00:00 2001 From: Akis Date: Sat, 7 Jan 2023 19:29:58 +0200 Subject: [PATCH] add pubnix --- src/lib/Form/Meta.svelte | 47 +++++++++++----- src/lib/Nav.svelte | 9 ++-- src/routes/contact/+page.svelte | 1 + src/routes/pubnix/+page.server.ts | 15 ++++++ src/routes/pubnix/+page.svelte | 63 ++++++++++++++++++++++ src/routes/pubnix/faq/+page.svelte | 12 +++++ src/routes/pubnix/register/+page.server.ts | 40 ++++++++++++++ src/routes/pubnix/register/+page.svelte | 41 ++++++++++++++ src/routes/pubnix/users/+page.server.ts | 15 ++++++ src/routes/pubnix/users/+page.svelte | 38 +++++++++++++ uno.config.ts | 2 +- 11 files changed, 264 insertions(+), 19 deletions(-) create mode 100644 src/routes/pubnix/+page.server.ts create mode 100644 src/routes/pubnix/+page.svelte create mode 100644 src/routes/pubnix/faq/+page.svelte create mode 100644 src/routes/pubnix/register/+page.server.ts create mode 100644 src/routes/pubnix/register/+page.svelte create mode 100644 src/routes/pubnix/users/+page.server.ts create mode 100644 src/routes/pubnix/users/+page.svelte diff --git a/src/lib/Form/Meta.svelte b/src/lib/Form/Meta.svelte index 761f124..de8f6bd 100644 --- a/src/lib/Form/Meta.svelte +++ b/src/lib/Form/Meta.svelte @@ -1,7 +1,13 @@
- + {#if input2} + + {/if} + {#if select} + + {/if}
- + +{/if} diff --git a/src/lib/Nav.svelte b/src/lib/Nav.svelte index ed57a2e..6ddea71 100644 --- a/src/lib/Nav.svelte +++ b/src/lib/Nav.svelte @@ -10,13 +10,13 @@ let innerWidth: number = 0; - $: showMenuButton = innerWidth < 1030; + $: showMenuButton = innerWidth < 1090; let menuOpen = false; - $: menuOpen = innerWidth > 1030; + $: menuOpen = innerWidth > 1090; - $: menuOpenMobile = innerWidth < 1030 && menuOpen; + $: menuOpenMobile = innerWidth < 1090 && menuOpen; let showThemeToggle: boolean = true; @@ -35,6 +35,7 @@ const menus = [ { name: "Instances", url: "/instances" }, { name: "Donate", url: "/donate" }, + { name: "Pubnix", url: "/pubnix" }, { name: "Contact us", url: "/contact" }, { name: "Our team", url: "/team" }, { name: "Timeline", url: "/timeline" }, @@ -160,7 +161,7 @@ @apply border-b border-b-solid border-b-grey; } - @media (min-width: 1030px) { + @media (min-width: 1090px) { .hasJS { flex-direction: row; padding-top: 0; diff --git a/src/routes/contact/+page.svelte b/src/routes/contact/+page.svelte index 09ef2b9..b61e019 100644 --- a/src/routes/contact/+page.svelte +++ b/src/routes/contact/+page.svelte @@ -26,6 +26,7 @@ /> diff --git a/src/routes/pubnix/+page.server.ts b/src/routes/pubnix/+page.server.ts new file mode 100644 index 0000000..443c5ae --- /dev/null +++ b/src/routes/pubnix/+page.server.ts @@ -0,0 +1,15 @@ +import type { PageServerLoad } from "./$types"; + +export const load = (async ({ fetch }) => { + try { + const request = await fetch("https://publapi.projectsegfau.lt/online"); + + if (request.ok) { + return request.json(); + } else { + return { error: true, message: "Error: " + request.status }; + } + } catch (err) { + return { error: true, message: "Error: " + err }; + } +}) satisfies PageServerLoad; diff --git a/src/routes/pubnix/+page.svelte b/src/routes/pubnix/+page.svelte new file mode 100644 index 0000000..fecc162 --- /dev/null +++ b/src/routes/pubnix/+page.svelte @@ -0,0 +1,63 @@ + + + + Pubnix | Project Segfault + + + +

+ Project Segfault pubnix +

+
+ + + +
+
+ +
+

Online users

+ + {#if !data.error} + {#if data.users.length > 0} +
+ {#each data.users as user} +
+
+ {user.username} + {user.email} +
+
+ Joined + {user.joined} +
+
+ {/each} +
+ {:else} +

No users online

+ {/if} + {:else} +

{data.message}

+ {/if} +
\ No newline at end of file diff --git a/src/routes/pubnix/faq/+page.svelte b/src/routes/pubnix/faq/+page.svelte new file mode 100644 index 0000000..f7bb455 --- /dev/null +++ b/src/routes/pubnix/faq/+page.svelte @@ -0,0 +1,12 @@ + + Pubnix FAQ | Project Segfault + + +
+

Pubnix FAQ

+ +

Here are some frequently asked questions about the pubnix.

+ +

What is a pubnix?

+ A pubnix is a [[Unix?]] server provided by a person or a group to a group for non-commercial recreational goals. +
\ No newline at end of file diff --git a/src/routes/pubnix/register/+page.server.ts b/src/routes/pubnix/register/+page.server.ts new file mode 100644 index 0000000..b1e617d --- /dev/null +++ b/src/routes/pubnix/register/+page.server.ts @@ -0,0 +1,40 @@ +import type { Actions } from "./$types"; +import Joi from "joi"; +import { fail } from "@sveltejs/kit"; +import { env } from "$env/dynamic/private"; + +export const actions: Actions = { + default: async ({ request, fetch, getClientAddress }) => { + const formData = await request.formData(); + + const BodyTypeSchema = Joi.object({ + username: Joi.string().required(), + email: Joi.string().email().required() + }); + + if (BodyTypeSchema.validate(Object.fromEntries(formData.entries())).error) { + return fail(400, { error: true, message: String(BodyTypeSchema.validate(Object.fromEntries(formData.entries())).error) }); + } else { + const request = await fetch("https://publapi.projectsegfau.lt/signup", { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ + username: formData.get("username"), + email: formData.get("email"), + ip: getClientAddress() + }) + }).then((res) => res.json()) + .catch((err) => { + return fail(400, { error: true, message: "Error: " + err }); + }); + + if (request.ok) { + return { success: true, message: request.message, username: request.username, email: request.email }; + } else { + return fail(400, { error: true, message: "Error: " + request.status }); + } + } + } +} \ No newline at end of file diff --git a/src/routes/pubnix/register/+page.svelte b/src/routes/pubnix/register/+page.svelte new file mode 100644 index 0000000..fd81539 --- /dev/null +++ b/src/routes/pubnix/register/+page.svelte @@ -0,0 +1,41 @@ + + + + Pubnix registration | Project Segfault + + +
+

Pubnix registration

+
+ + + {#if form?.success} + {form.message} + {/if} + + {#if form?.error} + {form.message} + {/if} + + +
\ No newline at end of file diff --git a/src/routes/pubnix/users/+page.server.ts b/src/routes/pubnix/users/+page.server.ts new file mode 100644 index 0000000..fe50343 --- /dev/null +++ b/src/routes/pubnix/users/+page.server.ts @@ -0,0 +1,15 @@ +import type { PageServerLoad } from "./$types"; + +export const load = (async ({ fetch }) => { + try { + const request = await fetch("https://publapi.projectsegfau.lt/users"); + + if (request.ok) { + return request.json(); + } else { + return { error: true, message: "Error: " + request.status }; + } + } catch (err) { + return { error: true, message: "Error: " + err }; + } +}) satisfies PageServerLoad; diff --git a/src/routes/pubnix/users/+page.svelte b/src/routes/pubnix/users/+page.svelte new file mode 100644 index 0000000..df81ed4 --- /dev/null +++ b/src/routes/pubnix/users/+page.svelte @@ -0,0 +1,38 @@ + + + + Pubnix users | Project Segfault + + +
+

All users

+ + {#if !data.error} + {#if data.users.length > 0} +
+ {#each data.users as user} +
+
+ {user.username} + {user.email} +
+
+ Joined + {user.joined} +
+
+ {/each} +
+ {:else} +

There are no users

+ {/if} + {:else} +

{data.message}

+ {/if} +
\ No newline at end of file diff --git a/uno.config.ts b/uno.config.ts index 9d2e410..1daf89e 100644 --- a/uno.config.ts +++ b/uno.config.ts @@ -50,7 +50,7 @@ export default defineConfig({ lg: "1024px", xl: "1280px", "2xl": "1536px", - nav: "1030px" + nav: "1090px" } },