From 1b1d6693ef402d4d820d07c504b8c56015448466 Mon Sep 17 00:00:00 2001 From: LightQuantum Date: Thu, 4 Jul 2024 01:33:45 +0800 Subject: [PATCH 1/2] fix: do not crash when any server is offline --- src/rpcs.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/rpcs.tsx b/src/rpcs.tsx index 11d450d..b91ea53 100644 --- a/src/rpcs.tsx +++ b/src/rpcs.tsx @@ -31,8 +31,14 @@ const castFetcher = (fetcher: Fetcher) => fetcher; type FetcherArray = { [K in keyof T]: Fetcher }; type ResultArray = { [K in keyof T]: T[K] }; -const liftFetchers = (fetchers: FetcherArray): Fetcher, U[]> => { +const liftFetchers = (fetchers: FetcherArray, ignoreError: boolean): Fetcher, U[]> => { return async (inputs: U[]) => { + if (ignoreError) { + // @ts-ignore + const tryResults = await Promise.all(fetchers.map((fetcher, index) => fetcher(inputs[index]).catch(e => e))); + const results = tryResults.filter((x) => !(x instanceof Error)); + return results as ResultArray; + } // @ts-ignore const results = await Promise.all(fetchers.map((fetcher, index) => fetcher(inputs[index]))); return results as ResultArray; @@ -57,7 +63,7 @@ export const useLugReport = () => { error, isLoading, isValidating - } = useSWR(LUG_SERVERS, liftFetchers(LUG_SERVERS.map(() => lugFetcher))) + } = useSWR(LUG_SERVERS, liftFetchers(LUG_SERVERS.map(() => lugFetcher), true)) const mergedData = useMemo(() => { const merged = data?.map((data) => data.WorkerStatus).reduce((prev, x) => ({...prev, ...x})) if (merged !== undefined) { @@ -78,7 +84,7 @@ export const useError = (error: any) => { color: "red", title: "出错了", icon: , - message: error, + message: error.toString(), }) } }, [error]); From df36cb0c0b36cfc1808cd1a2ea8c8559366c8d41 Mon Sep 17 00:00:00 2001 From: LightQuantum Date: Thu, 4 Jul 2024 03:00:20 +0800 Subject: [PATCH 2/2] fix: ci --- .github/workflows/ci.yml | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7039bb..a1e4407 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,11 +13,34 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Use Node.js 20.x + + - uses: pnpm/action-setup@v4 + name: Install pnpm + with: + version: 9 + run_install: false + + - name: Install Node.js uses: actions/setup-node@v4 with: node-version: 20 + cache: 'pnpm' + + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - uses: actions/cache@v4 + name: Setup pnpm cache + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + - name: Install dependencies run: pnpm install + - name: Build run: pnpm build \ No newline at end of file