mirror of
https://github.com/YuzuZensai/Pien-Studio.git
synced 2026-09-02 14:18:35 +00:00
✨ feat: ui commit hash versioning on prod
This commit is contained in:
@@ -2,13 +2,22 @@
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
const BUILD_HASH = process.env.NEXT_PUBLIC_GIT_HASH || "unknown";
|
||||
const SHOULD_LOAD_DEV_HASH = process.env.NODE_ENV === "development" && BUILD_HASH === "unknown";
|
||||
|
||||
function formatHash(hash: string) {
|
||||
return hash === "unknown" ? hash : hash.slice(0, 7);
|
||||
}
|
||||
|
||||
export function Footer() {
|
||||
const [hash, setHash] = useState<string>("...");
|
||||
const [hash, setHash] = useState(formatHash(BUILD_HASH));
|
||||
|
||||
useEffect(() => {
|
||||
if (!SHOULD_LOAD_DEV_HASH) return;
|
||||
|
||||
fetch("/api/commit-hash")
|
||||
.then((res) => res.json())
|
||||
.then((data) => setHash(data.hash))
|
||||
.then((data: { hash?: string }) => setHash(formatHash(data.hash || "unknown")))
|
||||
.catch(() => setHash("unknown"));
|
||||
}, []);
|
||||
|
||||
@@ -17,4 +26,4 @@ export function Footer() {
|
||||
<span className="text-xs text-gray-400 font-mono">{hash}</span>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user