Skip to content

Commit

Permalink
Add data for info page
Browse files Browse the repository at this point in the history
  • Loading branch information
Zokhoi committed Dec 15, 2024
1 parent f8e33be commit 75d15e1
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 4 deletions.
3 changes: 3 additions & 0 deletions framerail/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 6 additions & 2 deletions framerail/src/lib/server/deepwell/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ async function processRawRequest(request: JSONRPCRequest): Promise<void> {
client.receive(data)
}

export async function ping(): void {
await client.request("ping")
export async function ping(): Promise<void> {
await client.request("ping", {})
}

export async function info(): Promise<Record<string, any>> {
return client.request("info", {})
}

console.info(`Using DEEPWELL service at ${DEEPWELL_URL}`)
41 changes: 41 additions & 0 deletions framerail/src/lib/server/load/info.ts
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions framerail/src/lib/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions framerail/src/routes/about/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { loadInfo } from "$lib/server/load/info"

export async function load({ request, cookies }) {
return loadInfo(request, cookies)
}
89 changes: 88 additions & 1 deletion framerail/src/routes/about/+page.svelte
Original file line number Diff line number Diff line change
@@ -1 +1,88 @@
<h1>UNTRANSLATED:TODO: info page</h1>
<script lang="ts">
import { page } from "$app/stores"
</script>

<h1>UNTRANSLATED: Info page</h1>

<textarea class="debug">{JSON.stringify($page, null, 2)}</textarea>

<table class="platform-info">
<tbody>
<tr class="info-header">
<th colspan="2">UT:Backend</th>
</tr>
<tr class="info-attribute-row">
<th class="info-attribute-name">UT:Package name</th>
<td class="info-attribute-value">{$page.data.backend.package.name}</td>
</tr>
<tr class="info-attribute-row">
<th class="info-attribute-name">UT:Package description</th>
<td class="info-attribute-value">{$page.data.backend.package.description}</td>
</tr>
<tr class="info-attribute-row">
<th class="info-attribute-name">UT:Package license</th>
<td class="info-attribute-value">{$page.data.backend.package.license}</td>
</tr>
<tr class="info-attribute-row">
<th class="info-attribute-name">UT:Package repository</th>
<td class="info-attribute-value">
<a href={$page.data.backend.package.repository}>
{$page.data.backend.package.repository}
</a>
</td>
</tr>
<tr class="info-attribute-row">
<th class="info-attribute-name">UT:Package version</th>
<td class="info-attribute-value">{$page.data.backend.package.version}</td>
</tr>
<tr class="info-attribute-row">
<th class="info-attribute-name">UT:Rustc version</th>
<td class="info-attribute-value">{$page.data.backend.compile_info.rustc_version}</td>
</tr>
</tbody>
<tbody>
<tr class="info-header">
<th colspan="2">UT:Frontend</th>
</tr>
<tr class="info-attribute-row">
<th class="info-attribute-name">UT:Package name</th>
<td class="info-attribute-value">{$page.data.frontend.name}</td>
</tr>
<tr class="info-attribute-row">
<th class="info-attribute-name">UT:Package description</th>
<td class="info-attribute-value">{$page.data.frontend.description}</td>
</tr>
<tr class="info-attribute-row">
<th class="info-attribute-name">UT:Package license</th>
<td class="info-attribute-value">{$page.data.frontend.license}</td>
</tr>
<tr class="info-attribute-row">
<th class="info-attribute-name">UT:Package repository</th>
<td class="info-attribute-value">
<a href={$page.data.frontend.repository}>
{$page.data.frontend.repository}
</a>
</td>
</tr>
<tr class="info-attribute-row">
<th class="info-attribute-name">UT:Package version</th>
<td class="info-attribute-value">{$page.data.frontend.version}</td>
</tr>
<tr class="info-attribute-row">
<th class="info-attribute-name">UT:Node version</th>
<td class="info-attribute-value">{$page.data.frontend.node}</td>
</tr>
<tr class="info-attribute-row">
<th class="info-attribute-name">UT:Pnpm version</th>
<td class="info-attribute-value">{$page.data.frontend.pnpm}</td>
</tr>
</tbody>
</table>

<style lang="scss">
table.platform-info {
.info-attribute-name {
text-align: left;
}
}
</style>
19 changes: 18 additions & 1 deletion framerail/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
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: {
host: "::",
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
}
}
}

Expand Down

0 comments on commit 75d15e1

Please sign in to comment.