mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 16:23:41 +08:00 
			
		
		
		
	feat: use commit time as version id
This commit is contained in:
		@@ -183,6 +183,19 @@ function UserPromptModal(props: { onClose?: () => void }) {
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function formatVersionDate(t: string) {
 | 
			
		||||
  const d = new Date(+t);
 | 
			
		||||
  const year = d.getUTCFullYear();
 | 
			
		||||
  const month = d.getUTCMonth() + 1;
 | 
			
		||||
  const day = d.getUTCDate();
 | 
			
		||||
 | 
			
		||||
  return [
 | 
			
		||||
    year.toString(),
 | 
			
		||||
    month.toString().padStart(2, "0"),
 | 
			
		||||
    day.toString().padStart(2, "0"),
 | 
			
		||||
  ].join("");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function Settings() {
 | 
			
		||||
  const navigate = useNavigate();
 | 
			
		||||
  const [showEmojiPicker, setShowEmojiPicker] = useState(false);
 | 
			
		||||
@@ -193,8 +206,8 @@ export function Settings() {
 | 
			
		||||
 | 
			
		||||
  const updateStore = useUpdateStore();
 | 
			
		||||
  const [checkingUpdate, setCheckingUpdate] = useState(false);
 | 
			
		||||
  const currentVersion = updateStore.version;
 | 
			
		||||
  const remoteId = updateStore.remoteVersion;
 | 
			
		||||
  const currentVersion = formatVersionDate(updateStore.version);
 | 
			
		||||
  const remoteId = formatVersionDate(updateStore.remoteVersion);
 | 
			
		||||
  const hasNewVersion = currentVersion !== remoteId;
 | 
			
		||||
 | 
			
		||||
  function checkUpdate(force = false) {
 | 
			
		||||
@@ -202,6 +215,15 @@ export function Settings() {
 | 
			
		||||
    updateStore.getLatestVersion(force).then(() => {
 | 
			
		||||
      setCheckingUpdate(false);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    console.log(
 | 
			
		||||
      "[Update] local version ",
 | 
			
		||||
      new Date(+updateStore.version).toLocaleString(),
 | 
			
		||||
    );
 | 
			
		||||
    console.log(
 | 
			
		||||
      "[Update] remote version ",
 | 
			
		||||
      new Date(+updateStore.remoteVersion).toLocaleString(),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const usage = {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,10 @@
 | 
			
		||||
const COMMIT_ID: string = (() => {
 | 
			
		||||
  try {
 | 
			
		||||
    const childProcess = require("child_process");
 | 
			
		||||
    return (
 | 
			
		||||
      childProcess
 | 
			
		||||
        // .execSync("git describe --tags --abbrev=0")
 | 
			
		||||
        .execSync("git rev-parse --short HEAD")
 | 
			
		||||
        .toString()
 | 
			
		||||
        .trim()
 | 
			
		||||
    );
 | 
			
		||||
    return childProcess
 | 
			
		||||
      .execSync('git log -1 --format="%at000" --date=unix')
 | 
			
		||||
      .toString()
 | 
			
		||||
      .trim();
 | 
			
		||||
  } catch (e) {
 | 
			
		||||
    console.error("[Build Config] No git or not from git repo.");
 | 
			
		||||
    return "unknown";
 | 
			
		||||
 
 | 
			
		||||
@@ -53,10 +53,9 @@ export const useUpdateStore = create<UpdateStore>()(
 | 
			
		||||
        }));
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
          // const data = await (await fetch(FETCH_TAG_URL)).json();
 | 
			
		||||
          // const remoteId = data[0].name as string;
 | 
			
		||||
          const data = await (await fetch(FETCH_COMMIT_URL)).json();
 | 
			
		||||
          const remoteId = (data[0].sha as string).substring(0, 7);
 | 
			
		||||
          const remoteCommitTime = data[0].commit.committer.date;
 | 
			
		||||
          const remoteId = new Date(remoteCommitTime).getTime().toString();
 | 
			
		||||
          set(() => ({
 | 
			
		||||
            remoteVersion: remoteId,
 | 
			
		||||
          }));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user