Keldos commited on
Commit
76699a6
·
1 Parent(s): a28d5b0

feat: config中加入是否启用更新检查

Browse files
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(),version_time=version_time()))
42
 
43
  with gr.Row().style(equal_height=True):
44
  with gr.Column(scale=5):
@@ -267,7 +267,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
267
  )
268
  changeProxyBtn = gr.Button(i18n("🔄 设置代理地址"))
269
  default_btn = gr.Button(i18n("🔙 恢复默认设置"))
270
- checkUpdateBtn = gr.Button(i18n("🔄 检查更新..."))
271
 
272
  gr.Markdown(CHUANHU_DESCRIPTION, elem_id="description")
273
  gr.HTML(get_html("footer.html").format(versions=versions_html()), elem_id="footer")
 
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()), visible=check_update)
42
 
43
  with gr.Row().style(equal_height=True):
44
  with gr.Column(scale=5):
 
267
  )
268
  changeProxyBtn = gr.Button(i18n("🔄 设置代理地址"))
269
  default_btn = gr.Button(i18n("🔙 恢复默认设置"))
270
+ checkUpdateBtn = gr.Button(i18n("🔄 检查更新..."), visible=check_update)
271
 
272
  gr.Markdown(CHUANHU_DESCRIPTION, elem_id="description")
273
  gr.HTML(get_html("footer.html").format(versions=versions_html()), elem_id="footer")
assets/custom.js CHANGED
@@ -24,6 +24,7 @@ var userLogged = false;
24
  var usernameGotten = false;
25
  var historyLoaded = false;
26
  var updateInfoGotten = false;
 
27
 
28
  var ga = document.getElementsByTagName("gradio-app");
29
  var targetNode = ga[0];
@@ -94,7 +95,8 @@ function gradioLoaded(mutations) {
94
  }
95
  if (updateToast) {
96
  const lastCheckTime = localStorage.getItem('lastCheckTime') || 0;
97
- if (currentTime - lastCheckTime > 3 * 24 * 60 * 60 * 1000 && !updateInfoGotten) {
 
98
  updateLatestVersion();
99
  }
100
  }
@@ -544,6 +546,7 @@ async function updateLatestVersion() {
544
  if (latestVersionTime) {
545
  if (localVersionTime < latestVersionTime) {
546
  latestVersionElement.textContent = latestVersion;
 
547
  if (!isInIframe) {openUpdateToast();}
548
  } else {
549
  noUpdate();
@@ -577,6 +580,8 @@ function manualCheckUpdate() {
577
  localStorage.setItem('lastCheckTime', currentTime);
578
  }
579
  function noUpdate() {
 
 
580
  const versionInfoElement = document.getElementById('version-info-title');
581
  const releaseNoteWrap = document.getElementById('release-note-wrap');
582
  const gotoUpdateBtn = document.getElementById('goto-update-btn');
 
24
  var usernameGotten = false;
25
  var historyLoaded = false;
26
  var updateInfoGotten = false;
27
+ var isLatestVersion = localStorage.getItem('isLatestVersion') || false;
28
 
29
  var ga = document.getElementsByTagName("gradio-app");
30
  var targetNode = ga[0];
 
95
  }
96
  if (updateToast) {
97
  const lastCheckTime = localStorage.getItem('lastCheckTime') || 0;
98
+ const longTimeNoCheck = currentTime - lastCheckTime > 3 * 24 * 60 * 60 * 1000;
99
+ if (longTimeNoCheck && !updateInfoGotten && !isLatestVersion || isLatestVersion && !updateInfoGotten ) {
100
  updateLatestVersion();
101
  }
102
  }
 
546
  if (latestVersionTime) {
547
  if (localVersionTime < latestVersionTime) {
548
  latestVersionElement.textContent = latestVersion;
549
+ console.log(`New version ${latestVersion} found!`);
550
  if (!isInIframe) {openUpdateToast();}
551
  } else {
552
  noUpdate();
 
580
  localStorage.setItem('lastCheckTime', currentTime);
581
  }
582
  function noUpdate() {
583
+ localStorage.setItem('isLatestVersion', 'true');
584
+ isLatestVersion = true;
585
  const versionInfoElement = document.getElementById('version-info-title');
586
  const releaseNoteWrap = document.getElementById('release-note-wrap');
587
  const gotoUpdateBtn = document.getElementById('goto-update-btn');
config_example.json CHANGED
@@ -18,6 +18,7 @@
18
  "users": [], // 用户列表,[[用户名1, 密码1], [用户名2, 密码2], ...]
19
  "local_embedding": false, //是否在本地编制索引
20
  "hide_history_when_not_logged_in": false, //未登录情况下是否不展示对话历史
 
21
  "default_model": "gpt-3.5-turbo", // 默认模型
22
 
23
  //川虎助理设置
 
18
  "users": [], // 用户列表,[[用户名1, 密码1], [用户名2, 密码2], ...]
19
  "local_embedding": false, //是否在本地编制索引
20
  "hide_history_when_not_logged_in": false, //未登录情况下是否不展示对话历史
21
+ "check_update": true, //是否启用检查更新
22
  "default_model": "gpt-3.5-turbo", // 默认模型
23
 
24
  //川虎助理设置
modules/config.py CHANGED
@@ -23,6 +23,7 @@ __all__ = [
23
  "server_name",
24
  "server_port",
25
  "share",
 
26
  "hide_history_when_not_logged_in",
27
  "default_chuanhu_assistant_model"
28
  ]
@@ -39,6 +40,7 @@ lang_config = config.get("language", "auto")
39
  language = os.environ.get("LANGUAGE", lang_config)
40
 
41
  hide_history_when_not_logged_in = config.get("hide_history_when_not_logged_in", False)
 
42
 
43
  if os.path.exists("api_key.txt"):
44
  logging.info("检测到api_key.txt文件,正在进行迁移...")
 
23
  "server_name",
24
  "server_port",
25
  "share",
26
+ "check_update",
27
  "hide_history_when_not_logged_in",
28
  "default_chuanhu_assistant_model"
29
  ]
 
40
  language = os.environ.get("LANGUAGE", lang_config)
41
 
42
  hide_history_when_not_logged_in = config.get("hide_history_when_not_logged_in", False)
43
+ check_update = config.get("check_update", True)
44
 
45
  if os.path.exists("api_key.txt"):
46
  logging.info("检测到api_key.txt文件,正在进行迁移...")