diff --git a/scripts/get-version.js b/scripts/get-version.js new file mode 100644 index 0000000..eb601c7 --- /dev/null +++ b/scripts/get-version.js @@ -0,0 +1,7 @@ +const { execSync } = require("child_process"); + +// Get the short version of the git hash +const gitHash = execSync("git rev-parse --short HEAD").toString().trim(); + +// Write it to stdout +console.log(gitHash); diff --git a/src/components/CycleTransferStats.tsx b/src/components/CycleTransferStats.tsx index 60155c5..c2b0704 100644 --- a/src/components/CycleTransferStats.tsx +++ b/src/components/CycleTransferStats.tsx @@ -18,31 +18,35 @@ export const CycleTransferStatsCard: React.FC = ({ return null; } - return Object.entries(cycleData.server_name).map(([serverId, serverName]) => { - const transfer = cycleData.transfer?.[serverId] || 0; - const nextUpdate = cycleData.next_update?.[serverId]; + return Object.entries(cycleData.server_name).map( + ([serverId, serverName]) => { + const transfer = cycleData.transfer?.[serverId] || 0; + const nextUpdate = cycleData.next_update?.[serverId]; - if (!transfer && !nextUpdate) { - return null; - } + if (!transfer && !nextUpdate) { + return null; + } - return ( - - ); - }); + return ( + + ); + }, + ); })} ); diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index 25e703c..e91036c 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -9,7 +9,7 @@ const Footer: React.FC = () => {

- ©2020-{new Date().getFullYear()}{" "} + ©2020-{new Date().getFullYear()}{" "} Nezha @@ -22,6 +22,9 @@ const Footer: React.FC = () => { > nezha-dash + {import.meta.env.VITE_GIT_HASH && ( + ({import.meta.env.VITE_GIT_HASH}) + )}

diff --git a/src/components/ServiceTracker.tsx b/src/components/ServiceTracker.tsx index 6833ec0..72caaf3 100644 --- a/src/components/ServiceTracker.tsx +++ b/src/components/ServiceTracker.tsx @@ -37,7 +37,12 @@ export const ServiceTracker: React.FC = () => { }; if (isLoading) { - return
Loading...
; + return ( +
+ + Loading... +
+ ); } if ( @@ -58,22 +63,23 @@ export const ServiceTracker: React.FC = () => { /> )} - {serviceData.data.services && Object.keys(serviceData.data.services).length > 0 && ( -
- {Object.entries(serviceData.data.services).map(([name, data]) => { - const { days, uptime, avgDelay } = processServiceData(data); - return ( - - ); - })} -
- )} + {serviceData.data.services && + Object.keys(serviceData.data.services).length > 0 && ( +
+ {Object.entries(serviceData.data.services).map(([name, data]) => { + const { days, uptime, avgDelay } = processServiceData(data); + return ( + + ); + })} +
+ )} ); }; diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 584b424..3154780 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -123,15 +123,15 @@ interface BillingData { amount: string; } -interface PlanData { - bandwidth: string; - trafficVol: string; - trafficType: string; - IPv4: string; - IPv6: string; - networkRoute: string; - extra: string; -} +// interface PlanData { +// bandwidth: string; +// trafficVol: string; +// trafficType: string; +// IPv4: string; +// IPv6: string; +// networkRoute: string; +// extra: string; +// } interface PublicNoteData { billingDataMod: BillingData; @@ -151,7 +151,7 @@ export function parsePublicNote(publicNote: string): PublicNoteData | null { autoRenewal: data.billingDataMod.autoRenewal || "", cycle: data.billingDataMod.cycle || "", amount: data.billingDataMod.amount || "", - } + }, // planDataMod: { // bandwidth: data.planDataMod.bandwidth || "", // trafficVol: data.planDataMod.trafficVol || "", diff --git a/vite.config.ts b/vite.config.ts index c487293..4107898 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,10 +2,24 @@ import path from "path"; import { defineConfig } from "vite"; import react from "@vitejs/plugin-react-swc"; import { VitePWA } from "vite-plugin-pwa"; +import { execSync } from "child_process"; + +// Get git commit hash +const getGitHash = () => { + try { + return execSync("git rev-parse --short HEAD").toString().trim(); + } catch (e) { + console.log(e); + return "unknown"; + } +}; // https://vite.dev/config/ export default defineConfig({ base: "/", + define: { + "import.meta.env.VITE_GIT_HASH": JSON.stringify(getGitHash()), + }, plugins: [ react(), VitePWA({