feat: add hash tag

This commit is contained in:
hamster1963 2024-12-03 15:16:36 +08:00
parent 8811904133
commit b84be53ab8
6 changed files with 85 additions and 51 deletions

7
scripts/get-version.js Normal file
View File

@ -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);

View File

@ -18,31 +18,35 @@ export const CycleTransferStatsCard: React.FC<CycleTransferStatsProps> = ({
return null; return null;
} }
return Object.entries(cycleData.server_name).map(([serverId, serverName]) => { return Object.entries(cycleData.server_name).map(
const transfer = cycleData.transfer?.[serverId] || 0; ([serverId, serverName]) => {
const nextUpdate = cycleData.next_update?.[serverId]; const transfer = cycleData.transfer?.[serverId] || 0;
const nextUpdate = cycleData.next_update?.[serverId];
if (!transfer && !nextUpdate) { if (!transfer && !nextUpdate) {
return null; return null;
} }
return ( return (
<CycleTransferStatsClient <CycleTransferStatsClient
key={`${cycleId}-${serverId}`} key={`${cycleId}-${serverId}`}
name={cycleData.name} name={cycleData.name}
from={cycleData.from} from={cycleData.from}
to={cycleData.to} to={cycleData.to}
max={cycleData.max} max={cycleData.max}
serverStats={[{ serverStats={[
serverId, {
serverName, serverId,
transfer, serverName,
nextUpdate: nextUpdate || "", transfer,
}]} nextUpdate: nextUpdate || "",
className={className} },
/> ]}
); className={className}
}); />
);
},
);
})} })}
</section> </section>
); );

View File

@ -9,7 +9,7 @@ const Footer: React.FC = () => {
<section className="flex flex-col"> <section className="flex flex-col">
<section className="mt-1 flex items-center justify-between gap-2 text-[13px] font-light tracking-tight text-neutral-600/50 dark:text-neutral-300/50"> <section className="mt-1 flex items-center justify-between gap-2 text-[13px] font-light tracking-tight text-neutral-600/50 dark:text-neutral-300/50">
<p> <p>
©2020-{new Date().getFullYear()}{" "} &copy;2020-{new Date().getFullYear()}{" "}
<a href={"https://github.com/naiba/nezha"} target="_blank"> <a href={"https://github.com/naiba/nezha"} target="_blank">
Nezha Nezha
</a> </a>
@ -22,6 +22,9 @@ const Footer: React.FC = () => {
> >
nezha-dash nezha-dash
</a> </a>
{import.meta.env.VITE_GIT_HASH && (
<span className="ml-1">({import.meta.env.VITE_GIT_HASH})</span>
)}
</p> </p>
</section> </section>
</section> </section>

View File

@ -37,7 +37,12 @@ export const ServiceTracker: React.FC = () => {
}; };
if (isLoading) { if (isLoading) {
return <div className="mt-4 text-sm font-medium flex items-center gap-1"><Loader visible={true} />Loading...</div>; return (
<div className="mt-4 text-sm font-medium flex items-center gap-1">
<Loader visible={true} />
Loading...
</div>
);
} }
if ( if (
@ -58,22 +63,23 @@ export const ServiceTracker: React.FC = () => {
/> />
</div> </div>
)} )}
{serviceData.data.services && Object.keys(serviceData.data.services).length > 0 && ( {serviceData.data.services &&
<section className="grid grid-cols-1 md:grid-cols-2 mt-4 gap-2 md:gap-4"> Object.keys(serviceData.data.services).length > 0 && (
{Object.entries(serviceData.data.services).map(([name, data]) => { <section className="grid grid-cols-1 md:grid-cols-2 mt-4 gap-2 md:gap-4">
const { days, uptime, avgDelay } = processServiceData(data); {Object.entries(serviceData.data.services).map(([name, data]) => {
return ( const { days, uptime, avgDelay } = processServiceData(data);
<ServiceTrackerClient return (
key={name} <ServiceTrackerClient
days={days} key={name}
title={data.service.name} days={days}
uptime={uptime} title={data.service.name}
avgDelay={avgDelay} uptime={uptime}
/> avgDelay={avgDelay}
); />
})} );
</section> })}
)} </section>
)}
</div> </div>
); );
}; };

View File

@ -123,15 +123,15 @@ interface BillingData {
amount: string; amount: string;
} }
interface PlanData { // interface PlanData {
bandwidth: string; // bandwidth: string;
trafficVol: string; // trafficVol: string;
trafficType: string; // trafficType: string;
IPv4: string; // IPv4: string;
IPv6: string; // IPv6: string;
networkRoute: string; // networkRoute: string;
extra: string; // extra: string;
} // }
interface PublicNoteData { interface PublicNoteData {
billingDataMod: BillingData; billingDataMod: BillingData;
@ -151,7 +151,7 @@ export function parsePublicNote(publicNote: string): PublicNoteData | null {
autoRenewal: data.billingDataMod.autoRenewal || "", autoRenewal: data.billingDataMod.autoRenewal || "",
cycle: data.billingDataMod.cycle || "", cycle: data.billingDataMod.cycle || "",
amount: data.billingDataMod.amount || "", amount: data.billingDataMod.amount || "",
} },
// planDataMod: { // planDataMod: {
// bandwidth: data.planDataMod.bandwidth || "", // bandwidth: data.planDataMod.bandwidth || "",
// trafficVol: data.planDataMod.trafficVol || "", // trafficVol: data.planDataMod.trafficVol || "",

View File

@ -2,10 +2,24 @@ import path from "path";
import { defineConfig } from "vite"; import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc"; import react from "@vitejs/plugin-react-swc";
import { VitePWA } from "vite-plugin-pwa"; 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/ // https://vite.dev/config/
export default defineConfig({ export default defineConfig({
base: "/", base: "/",
define: {
"import.meta.env.VITE_GIT_HASH": JSON.stringify(getGitHash()),
},
plugins: [ plugins: [
react(), react(),
VitePWA({ VitePWA({