diff --git a/README.md b/README.md index 7569adf7..438bf5ee 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

-

Lsky Pro - Your photo album on the cloud.

+

Your photo album on the cloud.

[官网](https://www.lsky.pro)   [手册](https://www.kancloud.cn/wispx/lsky-pro)   diff --git a/application/index/controller/admin/System.php b/application/index/controller/admin/System.php index e018b346..a7832662 100644 --- a/application/index/controller/admin/System.php +++ b/application/index/controller/admin/System.php @@ -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('获取版本时遇到错误'); diff --git a/application/index/view/common/base.html b/application/index/view/common/base.html index fe21c2e2..aebaf499 100644 --- a/application/index/view/common/base.html +++ b/application/index/view/common/base.html @@ -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 @@ {if $user and $user.is_admin and !cookie('?no_update')} {/if} {$config.statistics_code|raw} diff --git a/extend/Upgrade.php b/extend/Upgrade.php index aeca57cd..b7b88611 100644 --- a/extend/Upgrade.php +++ b/extend/Upgrade.php @@ -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 正确安装'); diff --git a/public/static/app/js/app.js b/public/static/app/js/app.js index aa787f5d..fd8d8e07 100644 --- a/public/static/app/js/app.js +++ b/public/static/app/js/app.js @@ -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: '
升级中, 请不要关闭窗口...
' + }); + $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: '
' + marked(response.data.info) + '
', + title: '检测到新版本[' + response.version + ']', + content: '
' + marked(response.info) + '
', 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: '
更新中, 请不要关闭窗口...' - }); - // 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(); } } ]