diff --git a/app/components/settings.tsx b/app/components/settings.tsx index a426afcd..703f5ab7 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -23,7 +23,7 @@ import { import { Avatar, PromptHints } from "./home"; import Locale, { AllLangs, changeLang, getLang } from "../locales"; -import { getCurrentCommitId } from "../utils"; +import { getCurrentVersion } from "../utils"; import Link from "next/link"; import { UPDATE_URL } from "../constant"; import { SearchService, usePromptStore } from "../store/prompt"; @@ -60,7 +60,7 @@ export function Settings(props: { closeSettings: () => void }) { const updateStore = useUpdateStore(); const [checkingUpdate, setCheckingUpdate] = useState(false); - const currentId = getCurrentCommitId(); + const currentId = getCurrentVersion(); const remoteId = updateStore.remoteId; const hasNewVersion = currentId !== remoteId; diff --git a/app/constant.ts b/app/constant.ts index 818ef1fb..fff77607 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -3,3 +3,4 @@ export const REPO = "ChatGPT-Next-Web"; export const REPO_URL = `https://github.com/${OWNER}/${REPO}`; export const UPDATE_URL = `${REPO_URL}#%E4%BF%9D%E6%8C%81%E6%9B%B4%E6%96%B0-keep-updated`; export const FETCH_COMMIT_URL = `https://api.github.com/repos/${OWNER}/${REPO}/commits?per_page=1`; +export const FETCH_TAG_URL = `https://api.github.com/repos/${OWNER}/${REPO}/tags?per_page=1`; diff --git a/app/layout.tsx b/app/layout.tsx index 3a414046..cc8e45de 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -8,11 +8,11 @@ import { ACCESS_CODES, IS_IN_DOCKER } from "./api/access"; let COMMIT_ID: string | undefined; try { COMMIT_ID = process - .execSync("git rev-parse --short HEAD") + .execSync("git describe --tags --abbrev=0") .toString() .trim(); } catch (e) { - console.error("No git or not from git repo.") + console.error("No git or not from git repo."); } export const metadata = { @@ -22,13 +22,13 @@ export const metadata = { title: "ChatGPT Next Web", statusBarStyle: "black-translucent", }, - themeColor: "#fafafa" + themeColor: "#fafafa", }; function Meta() { const metas = { version: COMMIT_ID ?? "unknown", - access: (ACCESS_CODES.size > 0 || IS_IN_DOCKER) ? "enabled" : "disabled", + access: ACCESS_CODES.size > 0 || IS_IN_DOCKER ? "enabled" : "disabled", }; return ( diff --git a/app/store/update.ts b/app/store/update.ts index 118ea3ce..69f6cfee 100644 --- a/app/store/update.ts +++ b/app/store/update.ts @@ -1,7 +1,7 @@ import { create } from "zustand"; import { persist } from "zustand/middleware"; -import { FETCH_COMMIT_URL } from "../constant"; -import { getCurrentCommitId } from "../utils"; +import { FETCH_COMMIT_URL, FETCH_TAG_URL } from "../constant"; +import { getCurrentVersion } from "../utils"; export interface UpdateStore { lastUpdate: number; @@ -19,15 +19,15 @@ export const useUpdateStore = create()( remoteId: "", async getLatestCommitId(force = false) { - const overOneHour = Date.now() - get().lastUpdate > 3600 * 1000; - const shouldFetch = force || overOneHour; + const overTenMins = Date.now() - get().lastUpdate > 10 * 60 * 1000; + const shouldFetch = force || overTenMins; if (!shouldFetch) { - return getCurrentCommitId(); + return getCurrentVersion(); } try { - const data = await (await fetch(FETCH_COMMIT_URL)).json(); - const sha = data[0].sha as string; + const data = await (await fetch(FETCH_TAG_URL)).json(); + const sha = data[0].name as string; const remoteId = sha.substring(0, 7); set(() => ({ lastUpdate: Date.now(), @@ -37,13 +37,13 @@ export const useUpdateStore = create()( return remoteId; } catch (error) { console.error("[Fetch Upstream Commit Id]", error); - return getCurrentCommitId(); + return getCurrentVersion(); } }, }), { name: UPDATE_KEY, version: 1, - } - ) + }, + ), ); diff --git a/app/utils.ts b/app/utils.ts index 1ff7a064..64120df4 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -76,7 +76,7 @@ export function queryMeta(key: string, defaultValue?: string): string { } let currentId: string; -export function getCurrentCommitId() { +export function getCurrentVersion() { if (currentId) { return currentId; }