Spaces:
Sleeping
Sleeping
Keldos
commited on
Commit
·
a28d5b0
1
Parent(s):
9a6e0bf
feat: 改为使用标准UTC时间判断是否存在更新
Browse files细节:本地版本判断最新commit提交时间,远程release获取publish时间。
- ChuanhuChatbot.py +1 -1
- assets/custom.js +7 -4
- assets/html/update.html +1 -0
- modules/utils.py +10 -0
ChuanhuChatbot.py
CHANGED
@@ -38,7 +38,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
38 |
status_display = gr.Markdown(get_geoip(), elem_id="status_display")
|
39 |
with gr.Row(elem_id="float_display"):
|
40 |
user_info = gr.Markdown(value="getting user info...", elem_id="user_info")
|
41 |
-
update_info = gr.HTML(get_html("update.html").format(current_version=repo_html()))
|
42 |
|
43 |
with gr.Row().style(equal_height=True):
|
44 |
with gr.Column(scale=5):
|
|
|
38 |
status_display = gr.Markdown(get_geoip(), elem_id="status_display")
|
39 |
with gr.Row(elem_id="float_display"):
|
40 |
user_info = gr.Markdown(value="getting user info...", elem_id="user_info")
|
41 |
+
update_info = gr.HTML(get_html("update.html").format(current_version=repo_html(),version_time=version_time()))
|
42 |
|
43 |
with gr.Row().style(equal_height=True):
|
44 |
with gr.Column(scale=5):
|
assets/custom.js
CHANGED
@@ -529,6 +529,8 @@ async function updateLatestVersion() {
|
|
529 |
const latestVersionElement = document.getElementById('latest-version-title');
|
530 |
const releaseNoteElement = document.getElementById('release-note-content');
|
531 |
const currentVersion = currentVersionElement.textContent;
|
|
|
|
|
532 |
// const currentVersion = '20230619'; // for debugging
|
533 |
updateInfoGotten = true; //无论成功与否都只执行一次,否则容易api超限...
|
534 |
try {
|
@@ -538,9 +540,10 @@ async function updateLatestVersion() {
|
|
538 |
releaseNoteElement.innerHTML = marked.parse(releaseNote);
|
539 |
}
|
540 |
const latestVersion = data.tag_name;
|
541 |
-
|
542 |
-
|
543 |
-
if (
|
|
|
544 |
if (!isInIframe) {openUpdateToast();}
|
545 |
} else {
|
546 |
noUpdate();
|
@@ -560,8 +563,8 @@ function cancelUpdate() {
|
|
560 |
closeUpdateToast();
|
561 |
}
|
562 |
function openUpdateToast() {
|
563 |
-
setUpdateWindowHeight();
|
564 |
showingUpdateInfo = true;
|
|
|
565 |
}
|
566 |
function closeUpdateToast() {
|
567 |
updateToast.style.setProperty('top', '-500px');
|
|
|
529 |
const latestVersionElement = document.getElementById('latest-version-title');
|
530 |
const releaseNoteElement = document.getElementById('release-note-content');
|
531 |
const currentVersion = currentVersionElement.textContent;
|
532 |
+
const versionTime = document.getElementById('version-time').innerText;
|
533 |
+
const localVersionTime = versionTime !== "unknown" ? (new Date(versionTime)).getTime() : 0;
|
534 |
// const currentVersion = '20230619'; // for debugging
|
535 |
updateInfoGotten = true; //无论成功与否都只执行一次,否则容易api超限...
|
536 |
try {
|
|
|
540 |
releaseNoteElement.innerHTML = marked.parse(releaseNote);
|
541 |
}
|
542 |
const latestVersion = data.tag_name;
|
543 |
+
const latestVersionTime = (new Date(data.published_at)).getTime();
|
544 |
+
if (latestVersionTime) {
|
545 |
+
if (localVersionTime < latestVersionTime) {
|
546 |
+
latestVersionElement.textContent = latestVersion;
|
547 |
if (!isInIframe) {openUpdateToast();}
|
548 |
} else {
|
549 |
noUpdate();
|
|
|
563 |
closeUpdateToast();
|
564 |
}
|
565 |
function openUpdateToast() {
|
|
|
566 |
showingUpdateInfo = true;
|
567 |
+
setUpdateWindowHeight();
|
568 |
}
|
569 |
function closeUpdateToast() {
|
570 |
updateToast.style.setProperty('top', '-500px');
|
assets/html/update.html
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
<div id="check-chuanhu-update">
|
3 |
<p style="display:none">
|
4 |
<span id="current-version">{current_version}</span>
|
|
|
5 |
</p>
|
6 |
<p id="version-info-title">
|
7 |
Latest Version: <a href="https://github.com/gaizhenbiao/chuanhuchatgpt/releases/latest" target="_blank"
|
|
|
2 |
<div id="check-chuanhu-update">
|
3 |
<p style="display:none">
|
4 |
<span id="current-version">{current_version}</span>
|
5 |
+
<span id="version-time">{version_time}</span>
|
6 |
</p>
|
7 |
<p id="version-info-title">
|
8 |
Latest Version: <a href="https://github.com/gaizhenbiao/chuanhuchatgpt/releases/latest" target="_blank"
|
modules/utils.py
CHANGED
@@ -5,6 +5,7 @@ import logging
|
|
5 |
import json
|
6 |
import os
|
7 |
import datetime
|
|
|
8 |
import hashlib
|
9 |
import csv
|
10 |
import requests
|
@@ -579,6 +580,15 @@ def versions_html():
|
|
579 |
<a style="text-decoration:none;color:inherit" href="https://github.com/GaiZhenbiao/ChuanhuChatGPT">ChuanhuChat</a>: {repo_version}
|
580 |
"""
|
581 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
582 |
def get_html(filename):
|
583 |
path = os.path.join(shared.chuanhu_path, "assets", "html", filename)
|
584 |
if os.path.exists(path):
|
|
|
5 |
import json
|
6 |
import os
|
7 |
import datetime
|
8 |
+
from datetime import timezone
|
9 |
import hashlib
|
10 |
import csv
|
11 |
import requests
|
|
|
580 |
<a style="text-decoration:none;color:inherit" href="https://github.com/GaiZhenbiao/ChuanhuChatGPT">ChuanhuChat</a>: {repo_version}
|
581 |
"""
|
582 |
|
583 |
+
def version_time():
|
584 |
+
git = os.environ.get('GIT', "git")
|
585 |
+
try:
|
586 |
+
commit_time = run(f"{git} log -1 --format=%cd --date=iso-strict").strip()
|
587 |
+
commit_time = datetime.datetime.fromisoformat(commit_time).replace(tzinfo=timezone.utc).astimezone().strftime('%Y-%m-%dT%H:%M:%SZ')
|
588 |
+
except Exception:
|
589 |
+
commit_time = "unknown"
|
590 |
+
return commit_time
|
591 |
+
|
592 |
def get_html(filename):
|
593 |
path = os.path.join(shared.chuanhu_path, "assets", "html", filename)
|
594 |
if os.path.exists(path):
|