mirror of
https://github.com/Yidadaa/ChatGPT-Next-Web.git
synced 2025-08-08 07:10:16 +08:00
feat: add check update
This commit is contained in:
39
app/utils.ts
39
app/utils.ts
@@ -56,3 +56,42 @@ export function selectOrCopy(el: HTMLElement, content: string) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
let currentId: string;
|
||||
export function getCurrentCommitId() {
|
||||
if (currentId) {
|
||||
return currentId;
|
||||
}
|
||||
|
||||
if (document) {
|
||||
const meta = document.head.querySelector(
|
||||
"meta[name='version']"
|
||||
) as HTMLMetaElement;
|
||||
currentId = meta?.content ?? "";
|
||||
} else {
|
||||
currentId = process.env.COMMIT_ID ?? "";
|
||||
}
|
||||
|
||||
return currentId;
|
||||
}
|
||||
|
||||
let remoteId: string;
|
||||
export async function checkUpstreamLatestCommitId(force = false) {
|
||||
if (!force && remoteId) {
|
||||
return remoteId;
|
||||
}
|
||||
|
||||
const owner = "Yidadaa";
|
||||
const repo = "ChatGPT-Next-Web";
|
||||
const url = `https://api.github.com/repos/${owner}/${repo}/commits?per_page=1`;
|
||||
|
||||
try {
|
||||
const data = await (await fetch(url)).json();
|
||||
const sha = data[0].sha as string;
|
||||
remoteId = sha.substring(0, 7);
|
||||
return remoteId;
|
||||
} catch (error) {
|
||||
console.error("[Fetch Upstream Commit Id]", error);
|
||||
return getCurrentCommitId();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user