优化后台管理检测更新

This commit is contained in:
yangjian 2021-04-28 22:13:24 +08:00
parent f08ce79cd6
commit 1af152ac0c
2 changed files with 22 additions and 30 deletions

View File

@ -934,15 +934,17 @@ def admin_setting(request):
# 检测版本更新
def check_update(request):
url = ['https://gitee.com/api/v5/repos/zmister/MrDoc/tags','https://api.github.com/repos/zmister2016/MrDoc/tags']
resp1 = requests.get(url[0],timeout=5)
resp2 = requests.get(url[1],timeout=5)
if resp1.status_code == 200:
return JsonResponse({'status':True,'data':resp1.json()[-1]})
elif resp2.status_code == 200:
return JsonResponse({'status':True,'data':resp2.json()[0]})
gitee_url = 'https://gitee.com/api/v5/repos/zmister/MrDoc/tags'
github_url = 'https://api.github.com/repos/zmister2016/MrDoc/tags'
gitee_resp = requests.get(gitee_url,timeout=5)
if gitee_resp.status_code == 200:
return JsonResponse({'status':True,'data':gitee_resp.json()[-1]})
else:
return JsonResponse({'status':True,'data':{'name': 'v0.0.1'}})
github_resp = requests.get(github_url[1],timeout=5)
if github_resp.status_code == 200:
return JsonResponse({'status':True,'data':github_resp.json()[0]})
else:
return JsonResponse({'status':True,'data':{'name': 'v0.0.1'}})
# 后台管理

View File

@ -44,38 +44,28 @@
let $ = layui.jquery;
let layer = layui.layer;
// 检测版本更新
checkUpdate = function(){
checkUpdate = function(silence=false){
$.get("{% url 'check_update' %}",function(r){
// console.log(r)
if(r.status){
var new_version = r.data.name.slice(1,5)
var new_version = r.data.name.slice(1,6)
var current_version = '{{mrdoc_version}}'
// 如果存在新版本顶部提示div
console.log(new_version,current_version)
if(new_version > current_version){
$("#check_update_div").show()
layer.msg("发现新版本,请更新!")
console.log("发现新版本")
layer.open({
title:"{% trans '版本更新' %}",
content:"{% trans '觅道文档已发布新版本,请及时更新' %}",
})
}else{
layer.msg("当前已是最新版本!")
if(silence == false){
layer.msg("当前已是最新版本!")
}
}
}
})
}
var check_update = window.localStorage.getItem('check_update')
// console.log(check_update)
// 如果没有检测过,立即检测
if(check_update == null){
checkUpdate();
window.localStorage.setItem('check_update',new Date().getTime())
}else{
// 如果上次检测时间距今超过5天再次检测
var time_diff = (new Date().getTime() - check_update)/86400000
// console.log(time_diff)
if(time_diff > 5){
checkUpdate()
window.localStorage.setItem('check_update',new Date().getTime())
}
};
checkUpdate(silence=true);
})
</script>
{% block custom_script %}