From bdd7b1d1342492232ff48d22eca13e09b9e61cc2 Mon Sep 17 00:00:00 2001 From: million1156 Date: Fri, 22 Mar 2024 15:07:16 -0500 Subject: [PATCH 01/15] Add support for Android downloads --- src/routes/download/+page.svelte | 172 +++++++++++++++---------------- 1 file changed, 85 insertions(+), 87 deletions(-) diff --git a/src/routes/download/+page.svelte b/src/routes/download/+page.svelte index 0acb36c..a98f139 100644 --- a/src/routes/download/+page.svelte +++ b/src/routes/download/+page.svelte @@ -1,74 +1,76 @@ - Downloading Suyu @@ -94,24 +96,22 @@ stroke="white" /> - - -

- Downloading Suyu... -

- +

Downloading Suyu...

+ - -

Your download should start shortly. If it doesn't, click here Date: Fri, 22 Mar 2024 17:24:30 -0500 Subject: [PATCH 02/15] Add little "animation" (. -> .. -> ...), cleanup, & add support for the gitea instance --- src/routes/download/+page.svelte | 108 ++++++++++++++----------------- 1 file changed, 50 insertions(+), 58 deletions(-) diff --git a/src/routes/download/+page.svelte b/src/routes/download/+page.svelte index a98f139..f8ee7c9 100644 --- a/src/routes/download/+page.svelte +++ b/src/routes/download/+page.svelte @@ -1,45 +1,49 @@ - -

Downloading Suyu...

- + +

+ {@html htmlContent} +

Your download should start shortly. If it doesn't, click Date: Sun, 24 Mar 2024 07:15:16 +0300 Subject: [PATCH 03/15] feat: display commit count instead of gitlab stars on the homepage --- src/routes/+page.server.ts | 8 +++++++- src/routes/+page.svelte | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index 2ce74a2..d3beb6c 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -6,6 +6,7 @@ let starCount = 0; let roleMembers = { "1214817156420862012": 50, }; +let gitCommits = 0; async function fetchServerSideData() { console.log("Fetching member count"); @@ -26,18 +27,22 @@ async function fetchServerSideData() { }, }) : Promise.resolve({ json: () => ({ star_count: 0 }) }), // Default to 0 if no token is provided + fetch('https://git.suyu.dev/api/v1/repos/suyu/suyu/commits?stat=false&verification=false&files=false&limit=1') ]; - const [res, roles, gitlabRes] = await Promise.all(promises); + const [res, roles, gitlabRes, suyuGitRes] = await Promise.all(promises); const jsonPromises = [res.json(), roles.json(), gitlabRes.json()]; const [resJson, rolesJson, gitlabResJson] = await Promise.all(jsonPromises); + memberCount = resJson.approximate_member_count; starCount = gitlabResJson.star_count; + gitCommits = parseInt(suyuGitRes?.headers?.get('x-total'), 10) || 0; if (DISCORD_USER_TOKEN) roleMembers = rolesJson; console.log("Member count:", memberCount); console.log("Stars count:", starCount); + console.log('Git commit count', gitCommits); } if (!building) { @@ -52,5 +57,6 @@ export async function load({ cookies }) { memberCount, starCount, roleMembers, + gitCommits }; } diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 7447cf2..e5cd94b 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -10,6 +10,7 @@ $: memberCount = parseFloat(data.memberCount?.toPrecision(2)); $: contributors = parseFloat(data.roleMembers["1214817156420862012"]?.toPrecision(2)); $: starCount = parseFloat(data.starCount?.toPrecision(2)); + $: gitCommits = parseFloat(data.gitCommits?.toPrecision(2)); let metadata = { url: "https://suyu.dev", title: "suyu - Open-source, non-profit Switch emulator", @@ -116,7 +117,7 @@ >

By the numbers

- + From f27bd3a3450b8e1f037a573c8387d243dc297f19 Mon Sep 17 00:00:00 2001 From: Zekerocks011 <59491890+Zekerocks011@users.noreply.github.com> Date: Mon, 25 Mar 2024 14:30:43 -0400 Subject: [PATCH 04/15] Added Titles to All Links & Added a Temporary Link To Compatibility Google Sheet --- +layout.svelte | 445 +++++++++++++++++++++++++++++++++++++++++++++++++ +page.svelte | 279 +++++++++++++++++++++++++++++++ 2 files changed, 724 insertions(+) create mode 100644 +layout.svelte create mode 100644 +page.svelte diff --git a/+layout.svelte b/+layout.svelte new file mode 100644 index 0000000..90b8af6 --- /dev/null +++ b/+layout.svelte @@ -0,0 +1,445 @@ + + + +{#if navigator.userAgent.indexOf("Firefox") === -1} +
+ +
+{/if} + +
+
+ +
+
+ +
+
+ +
+
+
+ + {#each navItems as item, i} + toggleDropdown()} + > +

{item.name}

+
+ {/each} +
+
+ + {#key data.url} +
+ +
+ {/key} +
diff --git a/+page.svelte b/+page.svelte new file mode 100644 index 0000000..81ea910 --- /dev/null +++ b/+page.svelte @@ -0,0 +1,279 @@ + + + + {metadata.title} + + + + + + + + + + + + + + +
+ + + + +

+ suyu is a fully open-source + Switch emulator +

+

+ suyu is a familiar C++ based Switch emulator with a focus on compatibility. Completely free + and open-source, forever. +

+ +
+ +
+
+

By the numbers

+ + + + +
+
+
+
+ +
+
+
+
+ +
+

+ Built by and for the community +

+

+ The future of suyu is shaped by you. New features are always being added, and our community + continually shapes the direction of the project. +

+
+ + + +
+

+ we’re passionate about preserving games. +

+

+ We’re developing suyu as a tool to prevent Switch games from becoming lost media, so we’re + taking care to prevent dissolution from outside influences. +

+
+
+ + + +

suyu is community-run.

+
+
+ + + +

suyu is completely free. There’s no option to monetarily support the project.

+
+
+ + + +

suyu exists solely as an effort of hardware preservation and research.

+
+
+ + + +

suyu does not condone nor facilitate piracy or intellectual property theft.

+
+
+
+ +
From 70ac650c7e6fffd88c4469ee699b59a792f0317b Mon Sep 17 00:00:00 2001 From: million1156 Date: Mon, 25 Mar 2024 13:41:04 -0500 Subject: [PATCH 05/15] Fix invalid release --- src/routes/download/+page.svelte | 11 ++++++----- src/routes/faq/+page.svelte | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/routes/download/+page.svelte b/src/routes/download/+page.svelte index f8ee7c9..6243ac0 100644 --- a/src/routes/download/+page.svelte +++ b/src/routes/download/+page.svelte @@ -45,10 +45,11 @@ const releases = await response.json(); const latestRelease = releases[0].name; + console.log(latestRelease) // Release found if (latestRelease) { - console.log("Latest release tag:", latestRelease.name); - return latestRelease.name; // Assuming the first result is the latest + console.log("Latest release tag:", latestRelease); + return latestRelease; // Assuming the first result is the latest } else { console.log("No releases found."); return null; @@ -77,7 +78,7 @@ } else { window.location.href = `https://git.suyu.dev/suyu/suyu/releases/${latestRelease}/`; } - }, 3000); + }, 30000); }); @@ -107,13 +108,13 @@ /> -

+

{@html htmlContent}

Your download should start shortly. If it doesn't, click herehere.

diff --git a/src/routes/faq/+page.svelte b/src/routes/faq/+page.svelte index 741b64b..350fc9a 100644 --- a/src/routes/faq/+page.svelte +++ b/src/routes/faq/+page.svelte @@ -39,11 +39,11 @@

Q: What is the purpose of Suyu?

A: The purpose of this project is to provide a free, open-source alternative to the now-dead Yuzu emulator. We believe that the community should be able to emulate their Switch device (legally) and be able to enjoy their favorite game titles.

Q: How can I contribute to Suyu?

-

A: You can contribute to this project by submitting a pull request on our Git page. We are always looking for new contributors to help us improve the project!

+

A: You can contribute to this project by submitting a pull request on our Git page. We are always looking for new contributors to help us improve the project!

Q: Where can I download Suyu?

-

A: You can download the latest build of Suyu from our Git. Please make sure you are using the right URL!

+

A: You can download the latest build of Suyu from our Git. Please make sure you are using the right URL!

Q: What is the current progress for Suyu?

-

A: As of 3/20/2024, we have released our first Windows binary 🎉! You can find it here. We are always trying to make more and more progress, so please feel free to join the Discord!

+

A: As of 3/20/2024, we have released our first Windows binary 🎉! You can find it here. We are always trying to make more and more progress, so please feel free to join the Discord!


Email hosting lovingly provided by From b7df6dadd6fa32c51c20034ae721fd1e08202d56 Mon Sep 17 00:00:00 2001 From: million1156 Date: Mon, 25 Mar 2024 14:00:35 -0500 Subject: [PATCH 06/15] fix timeout (oopsie) --- src/routes/download/+page.svelte | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/routes/download/+page.svelte b/src/routes/download/+page.svelte index 6243ac0..25dd0d8 100644 --- a/src/routes/download/+page.svelte +++ b/src/routes/download/+page.svelte @@ -19,8 +19,7 @@ // Variables const UA = navigator.userAgent; const url = `https://git.suyu.dev/api/v1/repos/suyu/suyu/tags`; - const developerMode = false; - let timeout = 3000; + const fakeVersionTag = false; let latestRelease = ""; // Infinite timeout to test download workflow, comment out or disable developerMode if you don't want this @@ -59,7 +58,7 @@ return null; } } - if (!developerMode) { + if (!fakeVersionTag) { latestRelease = await getTag(); } else { latestRelease = "v0.0.1"; @@ -78,7 +77,7 @@ } else { window.location.href = `https://git.suyu.dev/suyu/suyu/releases/${latestRelease}/`; } - }, 30000); + }, 3000); }); From 55b3dfd8daa5f1c07d0045b970b43d3995da03ba Mon Sep 17 00:00:00 2001 From: Zekerocks011 <59491890+Zekerocks011@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:47:09 -0400 Subject: [PATCH 07/15] Update +layout.svelte Changed the FAQ titles from "Coming Soon" to "Frequently Asked Questions" --- +layout.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/+layout.svelte b/+layout.svelte index 90b8af6..5e0c69d 100644 --- a/+layout.svelte +++ b/+layout.svelte @@ -149,7 +149,7 @@ { name: "FAQ", href: "/faq", - title: "Coming Soon", + title: "Frequently Asked Questions", target: "_self", }, { @@ -309,7 +309,7 @@ > Blog Docs - FAQ + FAQ Compatibility
From 1affe83ff21bc7502ace01e5e7ffd2d695178f6a Mon Sep 17 00:00:00 2001 From: million1156 Date: Tue, 26 Mar 2024 19:27:46 -0500 Subject: [PATCH 08/15] comply with new naming scheme (curse you zqpvr01) --- src/routes/download/+page.svelte | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/routes/download/+page.svelte b/src/routes/download/+page.svelte index 25dd0d8..1e0f9e6 100644 --- a/src/routes/download/+page.svelte +++ b/src/routes/download/+page.svelte @@ -22,14 +22,6 @@ const fakeVersionTag = false; let latestRelease = ""; - // Infinite timeout to test download workflow, comment out or disable developerMode if you don't want this - // nvm this was bugging out lmao - /* if (developerMode) { - timeout = 9999; - return; - } */ - - // NOTE: I have no idea if this works.. Shoutout to the very smart person who blocked ALL API requests to the git server... async function getTag() { try { // Get the latest release tag @@ -67,13 +59,14 @@ setTimeout(() => { if (UA.includes("Windows")) { - window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/Suyu-Windows_x64.7z`; + window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/Suyu-Windows_x86_64.7z`; + // Android is above Linux because Android UA's also contain "Linux" } else if (UA.includes("Android")) { - window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/app-mainline-release.apk`; + window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/Suyu-Android_Arm64.apk`; } else if (UA.includes("Linux")) { - window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/suyu-mainline--.AppImage`; + window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/Suyu-Linux_x86_64.AppImage`; } else if (UA.includes("Macintosh;")) { - window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/suyu-macOS-arm64.dmg?inline=false`; + window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/Suyu-macOS-Arm64.dmg`; } else { window.location.href = `https://git.suyu.dev/suyu/suyu/releases/${latestRelease}/`; } From 4be4a685319cfd50fcb5498971ecded38193e99f Mon Sep 17 00:00:00 2001 From: million1156 Date: Tue, 26 Mar 2024 19:34:40 -0500 Subject: [PATCH 09/15] i have no idea how or why that happened --- src/routes/download/+page.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/download/+page.svelte b/src/routes/download/+page.svelte index 1e0f9e6..4ff241d 100644 --- a/src/routes/download/+page.svelte +++ b/src/routes/download/+page.svelte @@ -106,7 +106,7 @@

Your download should start shortly. If it doesn't, click herehere.

From 631cb61e8a03f9498ac71ca7f8225916b74db0e0 Mon Sep 17 00:00:00 2001 From: million1156 Date: Tue, 26 Mar 2024 19:35:55 -0500 Subject: [PATCH 10/15] a --- src/routes/download/+page.svelte | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/routes/download/+page.svelte b/src/routes/download/+page.svelte index 4ff241d..e9aeb34 100644 --- a/src/routes/download/+page.svelte +++ b/src/routes/download/+page.svelte @@ -36,7 +36,7 @@ const releases = await response.json(); const latestRelease = releases[0].name; - console.log(latestRelease) + console.log(latestRelease); // Release found if (latestRelease) { console.log("Latest release tag:", latestRelease); @@ -51,16 +51,16 @@ } } if (!fakeVersionTag) { - latestRelease = await getTag(); + latestRelease = await getTag(); } else { - latestRelease = "v0.0.1"; - console.log(latestRelease) + latestRelease = "v0.0.1"; + console.log(latestRelease); } setTimeout(() => { if (UA.includes("Windows")) { window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/Suyu-Windows_x86_64.7z`; - // Android is above Linux because Android UA's also contain "Linux" + // Android is above Linux because Android UA's also contain "Linux" } else if (UA.includes("Android")) { window.location.href = `https://git.suyu.dev/suyu/suyu/releases/download/${latestRelease}/Suyu-Android_Arm64.apk`; } else if (UA.includes("Linux")) { From 801bd34d9bb2644359c50c2d90e3011464783942 Mon Sep 17 00:00:00 2001 From: million1156 Date: Tue, 26 Mar 2024 19:41:22 -0500 Subject: [PATCH 11/15] Cleanup --- src/routes/download/+page.svelte | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/routes/download/+page.svelte b/src/routes/download/+page.svelte index e9aeb34..1173fcb 100644 --- a/src/routes/download/+page.svelte +++ b/src/routes/download/+page.svelte @@ -5,12 +5,13 @@ // cool moving dots :3 // NOTE: This is required to be ran on the server due to issues with Svelte let text = "Downloading Suyu"; + const textLength = text.length setInterval(() => { text += "."; - if (text.length > 19) { + // Text length + 3 is essentially the length of the text above + the 3 dots + if (text.length > textLength + 3) { text = "Downloading Suyu"; } - //console.log(text); }, 500); $: htmlContent = `${text}`; @@ -19,7 +20,7 @@ // Variables const UA = navigator.userAgent; const url = `https://git.suyu.dev/api/v1/repos/suyu/suyu/tags`; - const fakeVersionTag = false; + const fakeVersionTag = false; // Fake version tag? (for debugging) let latestRelease = ""; async function getTag() { From 5cee218403dd8065647d6ca6094aeb263f977f1d Mon Sep 17 00:00:00 2001 From: Million1156 Date: Wed, 27 Mar 2024 14:38:28 -0500 Subject: [PATCH 12/15] Fix star count --- src/routes/+page.server.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index 2ce74a2..281a8d6 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -19,21 +19,15 @@ async function fetchServerSideData() { }, }) : Promise.resolve({ json: () => roleMembers }), - GITLAB_API_TOKEN - ? fetch("https://gitlab.com/api/v4/projects/suyu-emu%2Fsuyu/", { - headers: { - Authorization: `Bearer ${GITLAB_API_TOKEN}`, - }, - }) - : Promise.resolve({ json: () => ({ star_count: 0 }) }), // Default to 0 if no token is provided + fetch("https://git.suyu.dev/api/v1/repos/suyu/suyu"), ]; const [res, roles, gitlabRes] = await Promise.all(promises); const jsonPromises = [res.json(), roles.json(), gitlabRes.json()]; - const [resJson, rolesJson, gitlabResJson] = await Promise.all(jsonPromises); + const [resJson, rolesJson, gitResJson] = await Promise.all(jsonPromises); memberCount = resJson.approximate_member_count; - starCount = gitlabResJson.star_count; + starCount = gitResJson.stars_count; if (DISCORD_USER_TOKEN) roleMembers = rolesJson; console.log("Member count:", memberCount); From 4cd72e9e46ee391efa9aac72f3af58c8cf6bdebf Mon Sep 17 00:00:00 2001 From: Million1156 Date: Wed, 27 Mar 2024 14:39:05 -0500 Subject: [PATCH 13/15] yes --- src/routes/+page.svelte | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 7447cf2..fbdcb5a 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -116,7 +116,8 @@ >

By the numbers

- + +
From 368e5ef0f3cbfdb5a67fb1ff024a076c744255f6 Mon Sep 17 00:00:00 2001 From: not-nullptr Date: Thu, 28 Mar 2024 13:34:06 +0000 Subject: [PATCH 14/15] fix page transitions --- src/lib/server/util/index.ts | 4 +- src/lib/util/api/index.ts | 4 +- src/routes/+page.svelte | 14 +++--- src/routes/account/+layout.svelte | 5 ++- src/routes/jwt/external/[audience]/+server.ts | 24 ++++++++++ src/routes/jwt/external/key.pem/+server.ts | 44 +++---------------- src/routes/jwt/internal/+server.ts | 2 +- src/routes/lobby/+server.ts | 8 ---- 8 files changed, 42 insertions(+), 63 deletions(-) create mode 100644 src/routes/jwt/external/[audience]/+server.ts diff --git a/src/lib/server/util/index.ts b/src/lib/server/util/index.ts index fb4030d..104afea 100644 --- a/src/lib/server/util/index.ts +++ b/src/lib/server/util/index.ts @@ -1,6 +1,6 @@ import type { IJwtData } from "$types/auth"; import type { Role } from "$types/db"; -import { PUBLIC_KEY } from "../secrets/secrets.json"; +import { PUB_KEY } from "$env/static/private"; import jwt from "jsonwebtoken"; export function json(body: T, status?: number): Response { @@ -14,7 +14,7 @@ export function json(body: T, status?: number): Response { export async function getJwtData(token: string): Promise { return new Promise((resolve, reject) => { - jwt.verify(token, PUBLIC_KEY, { algorithms: ["RS256"] }, (err, data) => { + jwt.verify(token, PUB_KEY, { algorithms: ["RS256"] }, (err, data) => { if (err) reject(err); else resolve(data as IJwtData); }); diff --git a/src/lib/util/api/index.ts b/src/lib/util/api/index.ts index b5c24e4..dbedfb6 100644 --- a/src/lib/util/api/index.ts +++ b/src/lib/util/api/index.ts @@ -1,6 +1,6 @@ import { userRepo } from "$lib/server/repo"; import type { SuyuUser } from "$lib/server/schema"; -import { PUBLIC_KEY } from "$lib/server/secrets/secrets.json"; +import { PUB_KEY } from "$env/static/private"; import type { IJwtData } from "$types/auth"; import cookie from "cookie"; import jwt from "jsonwebtoken"; @@ -18,7 +18,7 @@ export async function useAuth( } if (apiKey.startsWith("Bearer ")) { const token = apiKey.replace("Bearer ", ""); - const decoded: IJwtData = jwt.verify(token, Buffer.from(PUBLIC_KEY), { + const decoded: IJwtData = jwt.verify(token, Buffer.from(PUB_KEY), { algorithms: ["RS256"], }) as IJwtData; let user = await userRepo.findOne({ diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 7447cf2..4661e00 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -8,7 +8,7 @@ export let data: PageData; $: memberCount = parseFloat(data.memberCount?.toPrecision(2)); - $: contributors = parseFloat(data.roleMembers["1214817156420862012"]?.toPrecision(2)); + $: contributors = parseFloat(data.roleMembers?.["1214817156420862012"]?.toPrecision(2)); $: starCount = parseFloat(data.starCount?.toPrecision(2)); let metadata = { url: "https://suyu.dev", @@ -70,12 +70,8 @@ and open-source, forever.

- - Download + Download

Git

- Our Git instance is where all the magic of suyu happens. We're always looking for new contributors - to help us out, so feel free to check out our code. + Our Git instance is where all the magic of suyu happens. We're always looking for new + contributors to help us out, so feel free to check out our code.

(".navbar"); if (navBars.length !== 1) navBars.forEach((bar) => { @@ -52,6 +52,7 @@ const bounds = target.getBoundingClientRect(); const navBounds = navBar.getBoundingClientRect(); const pillBounds = indicator.getBoundingClientRect(); + if (ignoreAnimation) return; indicator.style.transform = `translateX(${bounds.left - navBounds.left}px)`; indicator.style.width = `${bounds.width}px`; if ( @@ -190,7 +191,7 @@ navClick(e, true)} class={`navitem flex flex-grow basis-[0] items-center justify-center whitespace-nowrap rounded-full px-4 py-2 text-sm font-bold ${ selected === i ? " text-[#a9a9a9] opacity-100" : "opacity-50" }`} diff --git a/src/routes/jwt/external/[audience]/+server.ts b/src/routes/jwt/external/[audience]/+server.ts new file mode 100644 index 0000000..9551a48 --- /dev/null +++ b/src/routes/jwt/external/[audience]/+server.ts @@ -0,0 +1,24 @@ +import { PRIVATE_KEY } from "$env/static/private"; +import { userRepo } from "$lib/server/repo/index.js"; +import { getJwtData } from "$lib/server/util/index.js"; +import { useAuth } from "$lib/util/api/index.js"; +import type { IJwtData } from "$types/auth.js"; +import jwt from "jsonwebtoken"; + +export async function POST({ request }) { + const jwtData = await getJwtData(request.headers.get("authorization")?.split(" ")[1] || ""); + const user = await userRepo.findOne({ + where: { + apiKey: jwtData.apiKey, + }, + }); + const token = jwt.sign({ ...user }, Buffer.from(PRIVATE_KEY), { + algorithm: "RS256", + }); + return new Response(token, { + status: 200, + headers: { + "content-type": "text/html", + }, + }); +} diff --git a/src/routes/jwt/external/key.pem/+server.ts b/src/routes/jwt/external/key.pem/+server.ts index ef8c292..a5815f2 100644 --- a/src/routes/jwt/external/key.pem/+server.ts +++ b/src/routes/jwt/external/key.pem/+server.ts @@ -1,45 +1,11 @@ -import { json } from "$lib/server/util/index.js"; +import { PUB_KEY } from "$env/static/private"; export function GET({ request }) { - return new Response( - `-----BEGIN CERTIFICATE----- -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== ------END CERTIFICATE-----`, - { - headers: { - "content-type": "text/plain", - }, + return new Response(PUB_KEY, { + headers: { + "content-type": "text/plain", }, - ); + }); } export function POST({ request }) { diff --git a/src/routes/jwt/internal/+server.ts b/src/routes/jwt/internal/+server.ts index ba144e7..a880dce 100644 --- a/src/routes/jwt/internal/+server.ts +++ b/src/routes/jwt/internal/+server.ts @@ -1,4 +1,4 @@ -import { PRIVATE_KEY } from "$lib/server/secrets/secrets.json"; +import { PRIVATE_KEY } from "$env/static/private"; import { useAuth } from "$lib/util/api/index.js"; import jwt from "jsonwebtoken"; diff --git a/src/routes/lobby/+server.ts b/src/routes/lobby/+server.ts index bb80a7d..650989a 100644 --- a/src/routes/lobby/+server.ts +++ b/src/routes/lobby/+server.ts @@ -1,7 +1,6 @@ import { Room, RoomManager } from "$lib/server/class/Room"; import { userRepo } from "$lib/server/repo/index.js"; import { SuyuUser } from "$lib/server/schema"; -import { PUBLIC_KEY } from "$lib/server/secrets/secrets.json"; import { json } from "$lib/server/util"; import { useAuth } from "$lib/util/api/index.js"; import type { IJwtData } from "$types/auth.js"; @@ -65,12 +64,5 @@ export async function POST({ request, getClientAddress }) { host: user, hasPassword: body.hasPassword || false, }); - console.log("Room added:", JSON.stringify(room, null, 2)); - // push every room to the top which starts with `[SUYU OFFICIAL]` and was created with username "suyu" - const suyuRoom = RoomManager.rooms.find((r) => r.roomInfo.name.startsWith("[SUYU OFFICIAL]")); - if (suyuRoom && suyuRoom.host.username === "suyu") { - RoomManager.rooms.splice(RoomManager.rooms.indexOf(suyuRoom), 1); - RoomManager.rooms.unshift(suyuRoom); - } return json(room.toJSON()); } From 4b07e715e7f906b1dc4ee5d9f3fc3a44495e75b8 Mon Sep 17 00:00:00 2001 From: Kaan Date: Thu, 28 Mar 2024 18:04:52 +0300 Subject: [PATCH 15/15] fix: display total commit count on homepage Also I've cleaned up the file a little bit. The commit count data only available as a response header value under the API path. This should be working as expected now. Let me know if there is an easier way to fetch this data. --- src/routes/+page.server.ts | 16 +++++++--------- src/routes/+page.svelte | 1 - 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index bc384a7..4927338 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -1,8 +1,7 @@ import { building } from "$app/environment"; -import { DISCORD_USER_TOKEN, GITLAB_API_TOKEN } from "$env/static/private"; +import { DISCORD_USER_TOKEN } from "$env/static/private"; let memberCount = 0; -let starCount = 0; let roleMembers = { "1214817156420862012": 50, }; @@ -20,20 +19,20 @@ async function fetchServerSideData() { }, }) : Promise.resolve({ json: () => roleMembers }), - fetch("https://git.suyu.dev/api/v1/repos/suyu/suyu"), + fetch('https://git.suyu.dev/api/v1/repos/suyu/suyu/commits?stat=false&verification=false&files=false&limit=1') ]; - const [res, roles, gitlabRes, suyuGitRes] = await Promise.all(promises); - const jsonPromises = [res.json(), roles.json(), gitlabRes.json()]; - const [resJson, rolesJson, gitResJson] = await Promise.all(jsonPromises); + const [res, roles, git] = await Promise.all(promises); + const jsonPromises = [res.json(), roles.json()]; + const [resJson, rolesJson] = await Promise.all(jsonPromises); memberCount = resJson.approximate_member_count; - gitCommits = parseInt(suyuGitRes?.headers?.get('x-total'), 10) || 0; + gitCommits = parseInt(git?.headers?.get('x-total'), 10) || 0; if (DISCORD_USER_TOKEN) roleMembers = rolesJson; console.log("Member count:", memberCount); - console.log('Git commit count', gitCommits); + console.log('Git commit count:', gitCommits); } if (!building) { @@ -46,7 +45,6 @@ export async function load({ cookies }) { return { tokenCookie: token, memberCount, - starCount, roleMembers, gitCommits }; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 8070ff2..1b13d73 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -9,7 +9,6 @@ export let data: PageData; $: memberCount = parseFloat(data.memberCount?.toPrecision(2)); $: contributors = parseFloat(data.roleMembers?.["1214817156420862012"]?.toPrecision(2)); - $: starCount = parseFloat(data.starCount?.toPrecision(2)); $: gitCommits = parseFloat(data.gitCommits?.toPrecision(2)); let metadata = { url: "https://suyu.dev",