diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index d9467fefb..b4a13985e 100755 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -6,6 +6,7 @@ use App\Module\Base; use App\Tasks\AutoArchivedTask; use App\Tasks\DeleteTmpTask; use App\Tasks\OverdueRemindEmailTask; +use Arr; use Hhxsv5\LaravelS\Swoole\Task\Task; use Redirect; use Request; @@ -45,11 +46,21 @@ class IndexController extends InvokeController */ public function version() { - return [ + $url = Base::getUrl(); + $package = Base::getPackage(); + $array = [ 'version' => Base::getVersion(), - 'owner' => 'kuaifan', - 'repo' => 'dootask', + 'publish' => Arr::get($package, 'app.0.publish'), ]; + if (is_array($package['app'])) { + foreach ($package['app'] as $item) { + if (is_array($item['publish']) && Base::hostContrast($url, $item['url'])) { + $array = $item['publish']; + break; + } + } + } + return $array; } /** @@ -87,9 +98,9 @@ class IndexController extends InvokeController */ public function desktop__publish($name = '') { - $genericVersion = Request::header('generic-version'); - // $latestFile = public_path("uploads/desktop/latest"); + $genericVersion = Request::header('generic-version'); + // 上传 if (preg_match("/^\d+\.\d+\.\d+$/", $genericVersion)) { $genericPath = "uploads/desktop/" . $genericVersion . "/"; $res = Base::upload([ @@ -103,6 +114,24 @@ class IndexController extends InvokeController } return $res; } + // 列表 + if (preg_match("/^\d+\.\d+\.\d+$/", $name)) { + $path = "uploads/desktop/{$name}"; + $dirPath = public_path($path); + $lists = Base::readDir($dirPath); + $files = []; + foreach ($lists as $file) { + $fileName = Base::leftDelete($file, $dirPath); + $files[] = [ + 'name' => substr($fileName, 1), + 'time' => date("Y-m-d H:i:s", fileatime($file)), + 'size' => Base::readableBytes(filesize($file)), + 'url' => Base::fillUrl($path . $fileName), + ]; + } + return view('desktop', ['version' => $name, 'files' => $files]); + } + // 下载 if ($name && file_exists($latestFile)) { $genericVersion = file_get_contents($latestFile); if (preg_match("/^\d+\.\d+\.\d+$/", $genericVersion)) { diff --git a/app/Module/Base.php b/app/Module/Base.php index 34360e7d1..6926a32a1 100755 --- a/app/Module/Base.php +++ b/app/Module/Base.php @@ -60,20 +60,30 @@ class Base ])->save(); } + /** + * 获取package配置文件 + * @return array + */ + public static function getPackage() + { + return Cache::remember("Base::package", now()->addSeconds(10), function () { + $file = base_path('package.json'); + if (file_exists($file)) { + $package = json_decode(file_get_contents($file), true); + return is_array($package) ? $package : []; + } + return []; + }); + } + /** * 获取版本号 * @return string */ public static function getVersion() { - return Cache::remember("Base::version", now()->addSeconds(10), function () { - $file = base_path('package.json'); - if (file_exists($file)) { - $packageArray = json_decode(file_get_contents($file), true); - return $packageArray['version'] ?? '1.0.0'; - } - return '1.0.0'; - }); + $package = self::getPackage(); + return $package['version'] ?? '1.0.0'; } /** @@ -2753,16 +2763,19 @@ class Base /** * 遍历获取文件 * @param $dir + * @param bool $subdirectory 是否遍历子目录 * @return array */ - public static function readDir($dir) + public static function readDir($dir, $subdirectory = true) { $files = array(); $dir_list = scandir($dir); foreach ($dir_list as $file) { if ($file != '..' && $file != '.') { if (is_dir($dir . '/' . $file)) { - $files = array_merge($files, self::readDir($dir . '/' . $file)); + if ($subdirectory) { + $files = array_merge($files, self::readDir($dir . '/' . $file, $subdirectory)); + } } else { $files[] = $dir . "/" . $file; } @@ -2992,6 +3005,18 @@ class Base return array_merge($matrix); } + /** + * 字节转格式 + * @param $bytes + * @return string + */ + public static function readableBytes($bytes) + { + $i = floor(log($bytes) / log(1024)); + $sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + return sprintf('%.02F', $bytes / pow(1024, $i)) * 1 . ' ' . $sizes[$i]; + } + /** * 去除emoji表情 * @param $str diff --git a/electron/electron.js b/electron/electron.js index 54718b228..6d3e68441 100644 --- a/electron/electron.js +++ b/electron/electron.js @@ -433,6 +433,9 @@ ipcMain.on('updateCheckAndDownload', (event, args) => { autoUpdater.setFeedURL(args) } autoUpdater.checkForUpdates().then(info => { + if (utils.compareVersion(config.version, info.updateInfo.version) >= 0) { + return + } if (args.apiVersion) { if (utils.compareVersion(info.updateInfo.version, args.apiVersion) === 0) { autoUpdating = utils.Time() diff --git a/resources/assets/js/components/RightBottom.vue b/resources/assets/js/components/RightBottom.vue index 54221ade4..692dfcea9 100644 --- a/resources/assets/js/components/RightBottom.vue +++ b/resources/assets/js/components/RightBottom.vue @@ -102,7 +102,7 @@ export default { }) } else { // 网页端提示下载 - this.getDownloadUrl(data) + this.getDownloadUrl(data.publish) } } }).catch(_ => { @@ -110,34 +110,45 @@ export default { }); }, - getDownloadUrl(data) { - let key = "cacheAppdown::" + this.apiVersion - let cache = $A.getStorageJson(key); - let timeout = 600; - if (cache.time && cache.time + timeout > Math.round(new Date().getTime() / 1000)) { - this.downloadUrl = cache.data.html_url; - setTimeout(this.checkVersion, timeout * 1000) + getDownloadUrl(publish) { + if (!$A.isJson(publish)) { return; } // - if (this.loadIng > 0) { - return; + switch (publish.provider) { + case 'generic': + this.downloadUrl = `${publish.url}/${this.apiVersion}` + break; + + case 'github': + let key = "cacheAppdown::" + this.apiVersion + let cache = $A.getStorageJson(key); + let timeout = 600; + if (cache.time && cache.time + timeout > Math.round(new Date().getTime() / 1000)) { + this.downloadUrl = cache.data.html_url; + setTimeout(this.checkVersion, timeout * 1000) + return; + } + // + if (this.loadIng > 0) { + return; + } + this.loadIng++; + axios.get(`https://api.github.com/repos/${publish.owner}/${publish.repo}/releases`).then(({status, data}) => { + this.loadIng--; + if (status === 200 && $A.isArray(data)) { + cache.time = Math.round(new Date().getTime() / 1000) + cache.data = data.find(({tag_name}) => this.compareVersion(this.tagVersion(tag_name), this.apiVersion) === 0) || {} + $A.setStorage(key, cache); + this.downloadUrl = cache.data.html_url; + } + setTimeout(this.checkVersion, timeout * 1000) + }).catch(() => { + this.loadIng--; + setTimeout(this.checkVersion, timeout * 1000) + }); + break; } - this.loadIng++; - // - axios.get(`https://api.github.com/repos/${data.owner}/${data.repo}/releases`).then(({status, data}) => { - this.loadIng--; - if (status === 200 && $A.isArray(data)) { - cache.time = Math.round(new Date().getTime() / 1000) - cache.data = data.find(({tag_name}) => this.compareVersion(this.tagVersion(tag_name), this.apiVersion) === 0) || {} - $A.setStorage(key, cache); - this.downloadUrl = cache.data.html_url; - } - setTimeout(this.checkVersion, timeout * 1000) - }).catch(() => { - this.loadIng--; - setTimeout(this.checkVersion, timeout * 1000) - }); }, updateQuitAndInstall() { diff --git a/resources/views/desktop.blade.php b/resources/views/desktop.blade.php new file mode 100755 index 000000000..f3d23c4b0 --- /dev/null +++ b/resources/views/desktop.blade.php @@ -0,0 +1,200 @@ + + +
+ + + + + + + + +| File Name | +File Size | +Date | +
|---|---|---|
| + | + | + |
| {{ $file['name'] }} | +{{ $file['size'] }} | +{{ $file['time'] }} | +
| List is empty | ++ | + |