feat: add check update

This commit is contained in:
Yifei Zhang
2023-03-23 16:01:00 +00:00
parent e55520e93c
commit 29de957395
13 changed files with 201 additions and 5257 deletions

View File

@@ -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();
}
}