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,7 +18,8 @@ export const CycleTransferStatsCard: React.FC<CycleTransferStatsProps> = ({
return null;
}
return Object.entries(cycleData.server_name).map(([serverId, serverName]) => {
return Object.entries(cycleData.server_name).map(
([serverId, serverName]) => {
const transfer = cycleData.transfer?.[serverId] || 0;
const nextUpdate = cycleData.next_update?.[serverId];
@ -33,16 +34,19 @@ export const CycleTransferStatsCard: React.FC<CycleTransferStatsProps> = ({
from={cycleData.from}
to={cycleData.to}
max={cycleData.max}
serverStats={[{
serverStats={[
{
serverId,
serverName,
transfer,
nextUpdate: nextUpdate || "",
}]}
},
]}
className={className}
/>
);
});
},
);
})}
</section>
);

View File

@ -9,7 +9,7 @@ const Footer: React.FC = () => {
<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">
<p>
©2020-{new Date().getFullYear()}{" "}
&copy;2020-{new Date().getFullYear()}{" "}
<a href={"https://github.com/naiba/nezha"} target="_blank">
Nezha
</a>
@ -22,6 +22,9 @@ const Footer: React.FC = () => {
>
nezha-dash
</a>
{import.meta.env.VITE_GIT_HASH && (
<span className="ml-1">({import.meta.env.VITE_GIT_HASH})</span>
)}
</p>
</section>
</section>

View File

@ -37,7 +37,12 @@ export const ServiceTracker: React.FC = () => {
};
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 (
@ -58,7 +63,8 @@ export const ServiceTracker: React.FC = () => {
/>
</div>
)}
{serviceData.data.services && Object.keys(serviceData.data.services).length > 0 && (
{serviceData.data.services &&
Object.keys(serviceData.data.services).length > 0 && (
<section className="grid grid-cols-1 md:grid-cols-2 mt-4 gap-2 md:gap-4">
{Object.entries(serviceData.data.services).map(([name, data]) => {
const { days, uptime, avgDelay } = processServiceData(data);

View File

@ -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 || "",

View File

@ -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({