mirror of
https://github.com/ChiChou/entdb.git
synced 2026-06-10 23:07:47 +02:00
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
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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!)}`,
|
||||
|
||||
@@ -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({
|
||||
<Breadcrumb>
|
||||
<BreadcrumbList>
|
||||
<BreadcrumbItem>
|
||||
<BreadcrumbLink href={addBasePath("/")}>Home</BreadcrumbLink>
|
||||
<BreadcrumbLink href={withBase("/")}>Home</BreadcrumbLink>
|
||||
</BreadcrumbItem>
|
||||
<BreadcrumbSeparator />
|
||||
<BreadcrumbItem>
|
||||
|
||||
+2
-2
@@ -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 <div className="p-8">Invalid OS</div>;
|
||||
}
|
||||
|
||||
redirect(addBasePath(`/os/keys?os=${os}`));
|
||||
redirect(withBase(`/os/keys?os=${os}`));
|
||||
}
|
||||
|
||||
@@ -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<string[]>)
|
||||
.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();
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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<OS[]> {
|
||||
|
||||
+3
-9
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user