Skip to content

Commit

Permalink
feat: add hash tag
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster1963 committed Dec 3, 2024
1 parent 8811904 commit b84be53
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 51 deletions.
7 changes: 7 additions & 0 deletions scripts/get-version.js
Original file line number Diff line number Diff line change
@@ -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);
50 changes: 27 additions & 23 deletions src/components/CycleTransferStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,35 @@ export const CycleTransferStatsCard: React.FC<CycleTransferStatsProps> = ({
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 (
<CycleTransferStatsClient
key={`${cycleId}-${serverId}`}
name={cycleData.name}
from={cycleData.from}
to={cycleData.to}
max={cycleData.max}
serverStats={[{
serverId,
serverName,
transfer,
nextUpdate: nextUpdate || "",
}]}
className={className}
/>
);
});
return (
<CycleTransferStatsClient
key={`${cycleId}-${serverId}`}
name={cycleData.name}
from={cycleData.from}
to={cycleData.to}
max={cycleData.max}
serverStats={[
{
serverId,
serverName,
transfer,
nextUpdate: nextUpdate || "",
},
]}
className={className}
/>
);
},
);
})}
</section>
);
Expand Down
5 changes: 4 additions & 1 deletion src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
40 changes: 23 additions & 17 deletions src/components/ServiceTracker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -58,22 +63,23 @@ export const ServiceTracker: React.FC = () => {
/>
</div>
)}
{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);
return (
<ServiceTrackerClient
key={name}
days={days}
title={data.service.name}
uptime={uptime}
avgDelay={avgDelay}
/>
);
})}
</section>
)}
{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);
return (
<ServiceTrackerClient
key={name}
days={days}
title={data.service.name}
uptime={uptime}
avgDelay={avgDelay}
/>
);
})}
</section>
)}
</div>
);
};
Expand Down
20 changes: 10 additions & 10 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 || "",
Expand Down
14 changes: 14 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit b84be53

Please sign in to comment.