From 53aeb562b7eac6daa46d98b48051f5078e49cf91 Mon Sep 17 00:00:00 2001 From: cc Date: Wed, 15 Apr 2026 17:10:29 +0200 Subject: [PATCH] Fetch data from separate GitHub Pages instead of bundling - Add NEXT_PUBLIC_DATA_URL env var pointing to entdb-data Pages - Refactor env.ts: dataURL, withBase (cleaner naming) - Remove data download step from build workflow --- .github/workflows/build.yml | 31 +++++------------------------ src/app/os/bin/page.tsx | 4 ++-- src/app/os/layout.tsx | 4 ++-- src/app/os/page.tsx | 4 ++-- src/components/oslist.tsx | 6 +++--- src/components/version-switcher.tsx | 4 ++-- src/lib/engine/kv.ts | 4 ++-- src/lib/env.ts | 12 +++-------- 8 files changed, 21 insertions(+), 48 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 13844a6..90f8599 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,9 +4,6 @@ on: push: branches: [main] - repository_dispatch: - types: [data-updated] - workflow_dispatch: permissions: @@ -14,6 +11,10 @@ permissions: pages: write id-token: write +env: + DATA_REPO_OWNER: ChiChou + DATA_REPO_NAME: entdb-data + jobs: build: runs-on: ubuntu-latest @@ -24,15 +25,6 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Show dispatch context - if: github.event_name == 'repository_dispatch' - run: | - echo "Triggered by repository_dispatch" - echo "event_type=${{ github.event.action }}" - echo "source_repo=${{ github.event.client_payload.source_repo }}" - echo "source_sha=${{ github.event.client_payload.source_sha }}" - echo "source_ref=${{ github.event.client_payload.source_ref }}" - - name: Setup Node.js uses: actions/setup-node@v4 with: @@ -53,20 +45,7 @@ jobs: run: npm run build env: NEXT_PUBLIC_BASE_PATH: ${{ steps.configure-pages.outputs.base_path || '' }} - - - name: Download latest data release - env: - GH_TOKEN: ${{ github.token }} - run: | - release_json=$(curl -fsSL \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer $GH_TOKEN" \ - https://api.github.com/repos/ChiChou/entdb-data/releases/latest) - - data_url=$(echo "$release_json" | jq -er '.assets[] | select(.name == "data.tar.gz") | .browser_download_url') - mkdir -p out/data - curl -fL "$data_url" -o data.tar.gz - tar -xzf data.tar.gz -C out/data + NEXT_PUBLIC_DATA_URL: https://${{ env.DATA_REPO_OWNER }}.github.io/${{ env.DATA_REPO_NAME }} - name: Upload artifact if: steps.configure-pages.outcome == 'success' diff --git a/src/app/os/bin/page.tsx b/src/app/os/bin/page.tsx index e3ff6c0..aedac03 100644 --- a/src/app/os/bin/page.tsx +++ b/src/app/os/bin/page.tsx @@ -15,7 +15,7 @@ import { CopyButton } from "@/components/copy-button"; import { DownloadButton } from "@/components/download-button"; import { DiffViewer } from "@/components/diff-viewer"; -import { addBasePath } from "@/lib/env"; +import { withBase } from "@/lib/env"; import { createEngine } from "@/lib/engine"; import type { PathHistory } from "@/lib/engine/types"; import { normalizePlist } from "@/lib/plist"; @@ -291,7 +291,7 @@ export default function BinaryDetail() { ], properties: { className: ["text-blue-600", "dark:text-blue-300", "hover:underline"], - href: addBasePath( + href: withBase( `/os/find?key=${encodeURIComponent( node.value as string, )}&os=${encodeURIComponent(os!)}`, diff --git a/src/app/os/layout.tsx b/src/app/os/layout.tsx index def3778..45cb8ac 100644 --- a/src/app/os/layout.tsx +++ b/src/app/os/layout.tsx @@ -12,7 +12,7 @@ import { } from "@/components/ui/breadcrumb"; import { VersionSwitcher } from "@/components/version-switcher"; -import { addBasePath } from "@/lib/env"; +import { withBase } from "@/lib/env"; import { useEffect } from "react"; import { usePathname } from "next/navigation"; @@ -46,7 +46,7 @@ export default function OSDetailLayout({ - Home + Home diff --git a/src/app/os/page.tsx b/src/app/os/page.tsx index fccd10e..bb6a605 100644 --- a/src/app/os/page.tsx +++ b/src/app/os/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { addBasePath } from "@/lib/env"; +import { withBase } from "@/lib/env"; import { useSearchParams, redirect } from "next/navigation"; export default function OSDetail() { @@ -11,5 +11,5 @@ export default function OSDetail() { return
Invalid OS
; } - redirect(addBasePath(`/os/keys?os=${os}`)); + redirect(withBase(`/os/keys?os=${os}`)); } diff --git a/src/components/oslist.tsx b/src/components/oslist.tsx index 5e3aaf2..4d21cdb 100644 --- a/src/components/oslist.tsx +++ b/src/components/oslist.tsx @@ -4,7 +4,7 @@ import Link from "next/link"; import { useEffect, useState, useMemo } from "react"; import { Group, OS } from "@/lib/types"; -import { addBasePath } from "@/lib/env"; +import { withBase, dataURL } from "@/lib/env"; import { Skeleton } from "./ui/skeleton"; function responseOK(r: Response) { @@ -108,14 +108,14 @@ export default function OSList() { useEffect(() => { setLoading(true); - fetch(addBasePath("/data/groups.json")) + fetch(`${dataURL}/groups.json`) .then(responseOK) .then((r) => r.json() as Promise) .then(async (groupList: string[]) => Promise.all( groupList.map(async (group) => { const response = await fetch( - addBasePath(`/data/${group}/list.json`), + `${dataURL}/${group}/list.json`, ).then(responseOK); const data = await response.json(); diff --git a/src/components/version-switcher.tsx b/src/components/version-switcher.tsx index cf54ae2..26990bf 100644 --- a/src/components/version-switcher.tsx +++ b/src/components/version-switcher.tsx @@ -12,7 +12,7 @@ import { Input } from "@/components/ui/input"; import { ChevronDown, Check } from "lucide-react"; import type { OS } from "@/lib/types"; -import { addBasePath, basePath } from "@/lib/env"; +import { withBase, basePath, dataURL } from "@/lib/env"; function compareVersion(a: string, b: string) { const l1 = a.split(".").map(Number); @@ -42,7 +42,7 @@ export function VersionSwitcher({ currentOs }: { currentOs: string }) { useEffect(() => { if (!group) return; - fetch(addBasePath(`/data/${group}/list.json`)) + fetch(`${dataURL}/${group}/list.json`) .then((r) => r.json()) .then((list: OS[]) => { list.sort((a, b) => compareVersion(a.version, b.version)); diff --git a/src/lib/engine/kv.ts b/src/lib/engine/kv.ts index 19d4496..d9c37fb 100644 --- a/src/lib/engine/kv.ts +++ b/src/lib/engine/kv.ts @@ -1,6 +1,6 @@ import type { Engine, PathHistory } from "./types"; import type { OS } from "@/lib/types"; -import { dataBaseURL } from "@/lib/env"; +import { dataURL } from "@/lib/env"; import { fetchText, fetchLines } from "@/lib/client"; interface KVRecord { @@ -55,7 +55,7 @@ export class KVEngine implements Engine { #baseURL: string; constructor(group: string) { - this.#baseURL = `${dataBaseURL()}/${group}`; + this.#baseURL = `${dataURL}/${group}`; } async listOS(): Promise { diff --git a/src/lib/env.ts b/src/lib/env.ts index da66da2..88bd161 100644 --- a/src/lib/env.ts +++ b/src/lib/env.ts @@ -1,11 +1,5 @@ export const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ""; +export const dataURL = process.env.NEXT_PUBLIC_DATA_URL || `${basePath}/data`; -export function addBasePath(path: string) { - let prefixed = path; - if (!prefixed.startsWith("/")) prefixed = `/${prefixed}`; - return basePath + prefixed; -} - -export function dataBaseURL(): string { - return addBasePath("/data"); -} +export const withBase = (path: string) => + basePath + (path.startsWith("/") ? path : `/${path}`);