✨ 完成平滑升级系统功能
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p align="center">Lsky Pro - Your photo album on the cloud.</p>
|
||||
<p align="center">Your photo album on the cloud.</p>
|
||||
|
||||
[官网](https://www.lsky.pro)
|
||||
[手册](https://www.kancloud.cn/wispx/lsky-pro)
|
||||
|
||||
@@ -94,7 +94,7 @@ class System extends Base
|
||||
Db::startTrans();
|
||||
$backup = 'backup-' . date('YmdHis') . '.zip';
|
||||
try {
|
||||
$upgrade = new \Upgrade(app()->getRootPath(), 'v' . $this->config['system_version']);
|
||||
$upgrade = new \Upgrade(app()->getRootPath(), $this->config['system_version']);
|
||||
$release = $upgrade->release(); // 获取最新版
|
||||
// 判断是否已经是最新版
|
||||
if ($upgrade->check($release->version)) {
|
||||
@@ -198,7 +198,7 @@ class System extends Base
|
||||
{
|
||||
$release = null;
|
||||
try {
|
||||
$upgrade = new \Upgrade(app()->getRootPath(), 'v' . $this->config['system_version']);
|
||||
$upgrade = new \Upgrade(app()->getRootPath(), $this->config['system_version']);
|
||||
$release = $upgrade->release(); // 获取安装包列表
|
||||
if (!$release) {
|
||||
throw new \Exception('获取版本时遇到错误');
|
||||
|
||||
@@ -173,7 +173,7 @@
|
||||
});
|
||||
|
||||
$('#update').click(function () {
|
||||
app.upgrade(true);
|
||||
app.getLastVer(ver, true);
|
||||
});
|
||||
|
||||
$('body').on('click', '.markdown-body a', function (e) {
|
||||
@@ -184,7 +184,7 @@
|
||||
</script>
|
||||
{if $user and $user.is_admin and !cookie('?no_update')}
|
||||
<script>
|
||||
app.upgrade(false);
|
||||
app.getLastVer(ver, false);
|
||||
</script>
|
||||
{/if}
|
||||
{$config.statistics_code|raw}
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ class Upgrade
|
||||
{
|
||||
$this->rootPath = rtrim(str_replace('\\', '/', $path), '/') . '/';
|
||||
$this->workspace = $this->rootPath . 'runtime/.tmp/';
|
||||
$this->version = $version;
|
||||
$this->version = ltrim('v', strtolower($version));
|
||||
|
||||
if (!class_exists('ZipArchive')) {
|
||||
throw new \Exception('无法继续执行, 请确保 ZipArchive 正确安装');
|
||||
|
||||
+64
-30
@@ -120,26 +120,79 @@ var app = {
|
||||
*/
|
||||
bytesToSize: function (bytes) {
|
||||
if (bytes === 0) return '0 B';
|
||||
var k = 1024, sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
var k = 1024, sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
||||
i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return (bytes / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i];
|
||||
},
|
||||
versionCompare: function (ver, newVer) {
|
||||
var sources = ver.split('.');
|
||||
var dests = newVer.split('.');
|
||||
var maxL = Math.max(sources.length, dests.length);
|
||||
var result = 0;
|
||||
for (var i = 0; i < maxL; i++) {
|
||||
let preValue = sources.length > i ? sources[i] : 0;
|
||||
let preNum = isNaN(Number(preValue)) ? preValue.charCodeAt() : Number(preValue);
|
||||
let lastValue = dests.length > i ? dests[i] : 0;
|
||||
let lastNum = isNaN(Number(lastValue)) ? lastValue.charCodeAt() : Number(lastValue);
|
||||
if (preNum < lastNum) {
|
||||
result = -1;
|
||||
break;
|
||||
} else if (preNum > lastNum) {
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
/**
|
||||
* 更新系统
|
||||
* 执行更新
|
||||
*/
|
||||
upgrade: function () {
|
||||
var loading = false;
|
||||
if (loading) return;
|
||||
loading = true;
|
||||
$d = mdui.dialog({
|
||||
overlay: true,
|
||||
modal: true,
|
||||
buttons: [],
|
||||
closeOnEsc: false,
|
||||
content: '<div class="mdui-valign"><div class="mdui-spinner mdui-spinner-colorful mr-3"></div> 升级中, 请不要关闭窗口...</div>'
|
||||
});
|
||||
$d.$dialog.css({'max-width': '300px'});
|
||||
mdui.mutation();
|
||||
setTimeout(function () {
|
||||
$.ajax({
|
||||
url: '/admin/system/upgrade.html',
|
||||
success: function (res) {
|
||||
$d.close();
|
||||
mdui.alert(res.msg, '系统提示', function() {
|
||||
res.code && history.go(0);
|
||||
});
|
||||
},
|
||||
complete: function () {
|
||||
loading = false;
|
||||
}
|
||||
});
|
||||
}, 1000)
|
||||
},
|
||||
/**
|
||||
* 检测版本更新
|
||||
* @param ver
|
||||
* @param auto
|
||||
*/
|
||||
upgrade: function (auto) {
|
||||
getLastVer: function (ver, auto) {
|
||||
$.ajax({
|
||||
url: '/admin/system/check.html',
|
||||
url: 'https://api.lsky.pro/releases.php?version=last',
|
||||
success: function (response) {
|
||||
if (response.code === 0) {
|
||||
if (app.versionCompare(ver, response.version) === 0) {
|
||||
// 已经是最新版
|
||||
auto && app.msg(true, '已经是最新版本');
|
||||
} else {
|
||||
var loading = false;
|
||||
if (!app.cookie.has('no_update') || auto) {
|
||||
mdui.dialog({
|
||||
title: '检测到新版本[' + response.data.version + ']',
|
||||
content: '<div class="markdown-body mdui-p-l-3 mdui-p-r-3">' + marked(response.data.info) + '</div>',
|
||||
title: '检测到新版本[' + response.version + ']',
|
||||
content: '<div class="markdown-body mdui-p-l-3 mdui-p-r-3">' + marked(response.info) + '</div>',
|
||||
modal: true,
|
||||
history: false,
|
||||
buttons: [
|
||||
@@ -148,35 +201,16 @@ var app = {
|
||||
},
|
||||
{
|
||||
text: '不再提示',
|
||||
onClick: function() {
|
||||
onClick: function () {
|
||||
app.cookie.set('no_update', true, 30, '/');
|
||||
}
|
||||
},
|
||||
{
|
||||
text: '立即更新',
|
||||
close: false,
|
||||
onClick: function(inst) {
|
||||
if (loading) return;
|
||||
loading = true;
|
||||
mdui.dialog({
|
||||
overlay: true,
|
||||
modal: true,
|
||||
buttons: [],
|
||||
closeOnEsc: false,
|
||||
content: '<div class="mdui-spinner mdui-spinner-colorful"></div> 更新中, 请不要关闭窗口...'
|
||||
});
|
||||
// TODO 请求更新
|
||||
/*$.ajax({
|
||||
url: '/admin/system/upgrade.html',
|
||||
success: function (res) {
|
||||
mdui.alert(res.msg, '系统提示', function() {
|
||||
res.code && history.go(0);
|
||||
});
|
||||
},
|
||||
complete: function () {
|
||||
loading = false;
|
||||
}
|
||||
});*/
|
||||
onClick: function (inst) {
|
||||
inst.close();
|
||||
app.upgrade();
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user