mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-08-09 04:02:41 +08:00
feat: #1000 ready to support client-side only
This commit is contained in:
@@ -2,7 +2,7 @@ import { create } from "zustand";
|
||||
import { persist } from "zustand/middleware";
|
||||
import { FETCH_COMMIT_URL, StoreKey } from "../constant";
|
||||
import { api } from "../client/api";
|
||||
import { showToast } from "../components/ui-lib";
|
||||
import { getClientConfig } from "../config/client";
|
||||
|
||||
export interface UpdateStore {
|
||||
lastUpdate: number;
|
||||
@@ -17,20 +17,6 @@ export interface UpdateStore {
|
||||
updateUsage: (force?: boolean) => Promise<void>;
|
||||
}
|
||||
|
||||
function queryMeta(key: string, defaultValue?: string): string {
|
||||
let ret: string;
|
||||
if (document) {
|
||||
const meta = document.head.querySelector(
|
||||
`meta[name='${key}']`,
|
||||
) as HTMLMetaElement;
|
||||
ret = meta?.content ?? "";
|
||||
} else {
|
||||
ret = defaultValue ?? "";
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const ONE_MINUTE = 60 * 1000;
|
||||
|
||||
export const useUpdateStore = create<UpdateStore>()(
|
||||
@@ -44,7 +30,7 @@ export const useUpdateStore = create<UpdateStore>()(
|
||||
version: "unknown",
|
||||
|
||||
async getLatestVersion(force = false) {
|
||||
set(() => ({ version: queryMeta("version") ?? "unknown" }));
|
||||
set(() => ({ version: getClientConfig()?.commitId ?? "unknown" }));
|
||||
|
||||
const overTenMins = Date.now() - get().lastUpdate > 10 * ONE_MINUTE;
|
||||
if (!force && !overTenMins) return;
|
||||
|
Reference in New Issue
Block a user