add-online-update

This commit is contained in:
Eason010212
2025-09-06 23:55:54 +08:00
parent 56bb5e7ca1
commit a6925ff0b7
6 changed files with 487 additions and 40 deletions

View File

@@ -70,11 +70,11 @@
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
当前服务器状态</div>
<div class="h5 mb-0 font-weight-bold text-gray-800"><%=status%></div>
平台类型</div>
<div class="h5 mb-0 font-weight-bold text-gray-800" id="platform"><%=platform%></div>
</div>
<div class="col-auto">
<i class="fa fa-history fa-2x text-gray-300"></i>
<i class="fa fa-code fa-2x text-gray-300"></i>
</div>
</div>
</div>
@@ -84,7 +84,7 @@
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
版本号</div>
MixIO版本号</div>
<div class="h5 mb-0 font-weight-bold text-gray-800"><%=version%></div>
</div>
<div class="col-auto">
@@ -93,6 +93,20 @@
</div>
</div>
</div>
<div class="card border-left-primary h-100 py-2" style="margin-bottom:15px">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
Mixly编程服务器版本号</div>
<div class="h5 mb-0 font-weight-bold text-gray-800"><%=versionmixly%></div>
</div>
<div class="col-auto">
<i class="fa fa-code fa-2x text-gray-300"></i>
</div>
</div>
</div>
</div>
<div class="card border-left-primary h-100 py-2">
<div class="card-body">
<div class="row no-gutters align-items-center">
@@ -108,12 +122,17 @@
</div>
</div>
<div class="row" style="display:flex;align-items:center;justify-content:center">
<button class="btn btn-lg btn-primary" style="margin-top:20px;margin-right:10px" onclick="fresh()"><i class="fa fa-refresh"></i> 刷新状态</button>
<button class="btn btn-lg btn-primary" style="margin-top:20px;margin-right:10px" onclick="fresh('mixio', '<%=platform%>')"><i class="fa fa-refresh"></i> 更新MixIO服务器</button>
</div>
<div class="row" style="display:flex;align-items:center;justify-content:center">
<button class="btn btn-lg btn-primary" style="margin-top:20px;margin-right:10px" onclick="fresh('mixly', 'all')"><i class="fa fa-refresh"></i> 更新Mixly编程服务器</button>
<!--
<% if (status=="运行中") { %>
<button class="btn btn-lg btn-danger" style="margin-top:20px;margin-left:10px" onclick="stopServer()"><i class="fa fa-ban"></i> 暂停服务器</button>
<%} else { %>
<button class="btn btn-lg btn-success" style="margin-top:20px;margin-left:10px" onclick="startServer()"><i class="fa fa-play"></i> 启动服务器</button>
<% } %>
-->
</div>
</div>
</div>
@@ -463,8 +482,91 @@
}
})
}
var fresh = function(){
window.location.href = window.location.href
var fresh = function(product, platform){
var textarea = $("<textarea readonly cols='50' rows='20' style='color:white; background-color:black'></textarea>")
var add_text = function(text){
textarea.text(textarea.text() + text + "\n")
textarea.scrollTop(textarea[0].scrollHeight);
}
var d = dialog({
content: textarea
});
d.showModal();
add_text("发送更新请求中...")
fetch('/api/check-update', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
product: product,
platform: platform
})
})
.then((response) => response.json())
.then((result) => {
add_text("本地版本:" + result["localVersion"])
add_text("云端版本:" + result["cloudVersion"])
add_text("需要更新:" + result["needsUpdate"])
var url = result["cloudFile"]
var error = result["error"]
if(error)
{
add_text(error)
}
if(result["needsUpdate"])
{
const eventSource = new EventSource(`/api/download?url=${encodeURIComponent(url)}&cloudVersion=${result["cloudVersion"]}`);
add_text("下载开始...")
eventSource.onmessage = function(event) {
console.log(event)
const data = JSON.parse(event.data);
console.log(data)
if (data.type === 'progress') {
add_text(`下载中: ${data.progress}%`)
}
else if (data.type === 'unzip') {
add_text(`解压中...`)
}
else if (data.type === 'complete') {
add_text(`${data.version}更新完成!`);
eventSource.close();
if(data.version == "mixio"){
setTimeout(
function(){
window.location.reload()
}
, 10000)
alert("更新已完成服务器将在10秒左右自动重启")
}
add_text('5秒后自动退出...');
setTimeout(function(){
d.close()
}, 5000)
window.location.reload()
}
};
eventSource.onerror = function(error) {
console.log(error)
add_text('下载失败5秒后自动退出...');
setTimeout(function(){
d.close()
}, 5000)
eventSource.close();
};
}
else
{
add_text("已经是最新版本5秒后自动退出...")
setTimeout(function(){
d.close()
}, 5000)
}
})
.catch((error) => {
add_text(error);
});
}
var view = function(index){
a = [1,2,3]