From 75d15e1361b65b7cd2ebcab4fc611226f553c86f Mon Sep 17 00:00:00 2001 From: Zokhoi <20432565+Zokhoi@users.noreply.github.com> Date: Sun, 15 Dec 2024 12:49:06 +0000 Subject: [PATCH] Add data for info page --- framerail/package.json | 3 + framerail/src/lib/server/deepwell/index.ts | 8 +- framerail/src/lib/server/load/info.ts | 41 ++++++++++ framerail/src/lib/vite-env.d.ts | 8 ++ framerail/src/routes/about/+page.server.ts | 5 ++ framerail/src/routes/about/+page.svelte | 89 +++++++++++++++++++++- framerail/vite.config.ts | 19 ++++- 7 files changed, 169 insertions(+), 4 deletions(-) create mode 100644 framerail/src/lib/server/load/info.ts create mode 100644 framerail/src/lib/vite-env.d.ts create mode 100644 framerail/src/routes/about/+page.server.ts diff --git a/framerail/package.json b/framerail/package.json index 7d76d46941..55b7887544 100644 --- a/framerail/package.json +++ b/framerail/package.json @@ -1,8 +1,11 @@ { "name": "framerail", "version": "2024.9.14", + "description": "Framerail - Wikijump frontend service", "type": "module", "private": true, + "repository": "https://github.com/scpwiki/wikijump/tree/develop/framerail", + "license": "AGPL-3.0-or-later", "scripts": { "dev": "vite dev", "build": "vite build", diff --git a/framerail/src/lib/server/deepwell/index.ts b/framerail/src/lib/server/deepwell/index.ts index 08c2b3ccea..97dbe23f73 100644 --- a/framerail/src/lib/server/deepwell/index.ts +++ b/framerail/src/lib/server/deepwell/index.ts @@ -18,8 +18,12 @@ async function processRawRequest(request: JSONRPCRequest): Promise { client.receive(data) } -export async function ping(): void { - await client.request("ping") +export async function ping(): Promise { + await client.request("ping", {}) +} + +export async function info(): Promise> { + return client.request("info", {}) } console.info(`Using DEEPWELL service at ${DEEPWELL_URL}`) diff --git a/framerail/src/lib/server/load/info.ts b/framerail/src/lib/server/load/info.ts new file mode 100644 index 0000000000..70210df978 --- /dev/null +++ b/framerail/src/lib/server/load/info.ts @@ -0,0 +1,41 @@ +import defaults from "$lib/defaults" +import { parseAcceptLangHeader } from "$lib/locales" +import { info } from "$lib/server/deepwell" +import { translate } from "$lib/server/deepwell/translate" +import type { TranslateKeys } from "$lib/types" +import "$lib/vite-env.d.ts" +import process from "process" + +export async function loadInfo(request, cookies) { + const url = new URL(request.url) + const domain = url.hostname + const sessionToken = cookies.get("wikijump_token") + let locales = parseAcceptLangHeader(request) + + if (!locales.includes(defaults.fallbackLocale)) locales.push(defaults.fallbackLocale) + + const response = await info() + + let translateKeys: TranslateKeys = { + ...defaults.translateKeys + } + + const viewData = { + backend: response, + frontend: { + name: serverInfo.frontendName, + description: serverInfo.frontendDescription, + repository: serverInfo.frontendRepository, + version: serverInfo.frontendVersion, + license: serverInfo.frontendLicense, + node: process.versions.node, + pnpm: serverInfo.pnpmVersion + } + } + + const translated = await translate(locales, translateKeys) + + viewData.internationalization = translated + + return viewData +} diff --git a/framerail/src/lib/vite-env.d.ts b/framerail/src/lib/vite-env.d.ts new file mode 100644 index 0000000000..c3c03cb706 --- /dev/null +++ b/framerail/src/lib/vite-env.d.ts @@ -0,0 +1,8 @@ +declare const serverInfo: { + pnpmVersion: string | null + frontendName: string | null + frontendVersion: string | null + frontendDescription: string | null + frontendRepository: string | null + frontendLicense: string | null +} diff --git a/framerail/src/routes/about/+page.server.ts b/framerail/src/routes/about/+page.server.ts new file mode 100644 index 0000000000..0b37345968 --- /dev/null +++ b/framerail/src/routes/about/+page.server.ts @@ -0,0 +1,5 @@ +import { loadInfo } from "$lib/server/load/info" + +export async function load({ request, cookies }) { + return loadInfo(request, cookies) +} diff --git a/framerail/src/routes/about/+page.svelte b/framerail/src/routes/about/+page.svelte index 2af25427f4..9e789c6ae1 100644 --- a/framerail/src/routes/about/+page.svelte +++ b/framerail/src/routes/about/+page.svelte @@ -1 +1,88 @@ -

UNTRANSLATED:TODO: info page

+ + +

UNTRANSLATED: Info page

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
UT:Backend
UT:Package name{$page.data.backend.package.name}
UT:Package description{$page.data.backend.package.description}
UT:Package license{$page.data.backend.package.license}
UT:Package repository + + {$page.data.backend.package.repository} + +
UT:Package version{$page.data.backend.package.version}
UT:Rustc version{$page.data.backend.compile_info.rustc_version}
UT:Frontend
UT:Package name{$page.data.frontend.name}
UT:Package description{$page.data.frontend.description}
UT:Package license{$page.data.frontend.license}
UT:Package repository + + {$page.data.frontend.repository} + +
UT:Package version{$page.data.frontend.version}
UT:Node version{$page.data.frontend.node}
UT:Pnpm version{$page.data.frontend.pnpm}
+ + \ No newline at end of file diff --git a/framerail/vite.config.ts b/framerail/vite.config.ts index bd9973280a..9974e4b696 100644 --- a/framerail/vite.config.ts +++ b/framerail/vite.config.ts @@ -1,5 +1,12 @@ import { sveltekit } from "@sveltejs/kit/vite" +import { execSync } from "child_process" import type { UserConfig } from "vite" +import pkg from "./package.json" + +let pnpmVersion = null +try { + pnpmVersion = execSync("pnpm -v").toString("utf-8").trim() +} catch (_) {} const config: UserConfig = { server: { @@ -7,7 +14,17 @@ const config: UserConfig = { port: 3000, strictPort: true }, - plugins: [sveltekit()] + plugins: [sveltekit()], + define: { + // also update $lib/vite-env.d.ts if these defines are changed + serverInfo: { + pnpmVersion, + frontendName: pkg.name ?? null, + frontendVersion: pkg.version ?? null, + frontendDescription: pkg.description ?? null, + frontendRepository: pkg.repository ?? null, + frontendLicense: pkg.license ?? null + } } }