forked from XiaoMo/ChatGPT-Next-Web
feat: use commit time as version id
This commit is contained in:
parent
074bd9f045
commit
fce3b3ce7b
@ -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() {
|
export function Settings() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [showEmojiPicker, setShowEmojiPicker] = useState(false);
|
const [showEmojiPicker, setShowEmojiPicker] = useState(false);
|
||||||
@ -193,8 +206,8 @@ export function Settings() {
|
|||||||
|
|
||||||
const updateStore = useUpdateStore();
|
const updateStore = useUpdateStore();
|
||||||
const [checkingUpdate, setCheckingUpdate] = useState(false);
|
const [checkingUpdate, setCheckingUpdate] = useState(false);
|
||||||
const currentVersion = updateStore.version;
|
const currentVersion = formatVersionDate(updateStore.version);
|
||||||
const remoteId = updateStore.remoteVersion;
|
const remoteId = formatVersionDate(updateStore.remoteVersion);
|
||||||
const hasNewVersion = currentVersion !== remoteId;
|
const hasNewVersion = currentVersion !== remoteId;
|
||||||
|
|
||||||
function checkUpdate(force = false) {
|
function checkUpdate(force = false) {
|
||||||
@ -202,6 +215,15 @@ export function Settings() {
|
|||||||
updateStore.getLatestVersion(force).then(() => {
|
updateStore.getLatestVersion(force).then(() => {
|
||||||
setCheckingUpdate(false);
|
setCheckingUpdate(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"[Update] local version ",
|
||||||
|
new Date(+updateStore.version).toLocaleString(),
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
"[Update] remote version ",
|
||||||
|
new Date(+updateStore.remoteVersion).toLocaleString(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const usage = {
|
const usage = {
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
const COMMIT_ID: string = (() => {
|
const COMMIT_ID: string = (() => {
|
||||||
try {
|
try {
|
||||||
const childProcess = require("child_process");
|
const childProcess = require("child_process");
|
||||||
return (
|
return childProcess
|
||||||
childProcess
|
.execSync('git log -1 --format="%at000" --date=unix')
|
||||||
// .execSync("git describe --tags --abbrev=0")
|
.toString()
|
||||||
.execSync("git rev-parse --short HEAD")
|
.trim();
|
||||||
.toString()
|
|
||||||
.trim()
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("[Build Config] No git or not from git repo.");
|
console.error("[Build Config] No git or not from git repo.");
|
||||||
return "unknown";
|
return "unknown";
|
||||||
|
@ -53,10 +53,9 @@ export const useUpdateStore = create<UpdateStore>()(
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
try {
|
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 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(() => ({
|
set(() => ({
|
||||||
remoteVersion: remoteId,
|
remoteVersion: remoteId,
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user