mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-11 18:42:54 +00:00
优化下载提示
This commit is contained in:
parent
7ba28a9770
commit
9ffc3520e7
@ -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)) {
|
||||
|
||||
@ -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
|
||||
|
||||
3
electron/electron.js
vendored
3
electron/electron.js
vendored
@ -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()
|
||||
|
||||
@ -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() {
|
||||
|
||||
200
resources/views/desktop.blade.php
Executable file
200
resources/views/desktop.blade.php
Executable file
@ -0,0 +1,200 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta name="format-detection" content="telephone=no" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
<title>{{ config('app.name', 'WebPage') }} - v{{ $version }}</title>
|
||||
<link rel="shortcut icon" href="{{ asset_main('favicon.ico') }}">
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 14px;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.mirror {
|
||||
overflow: auto;
|
||||
width: 1180px;
|
||||
margin: 0 auto 20px
|
||||
}
|
||||
|
||||
.mirror-nav {
|
||||
width: 1180px;
|
||||
margin: 20px auto 10px
|
||||
}
|
||||
|
||||
.table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
margin-bottom: 20px;
|
||||
font-size: 12pt
|
||||
}
|
||||
|
||||
td, th {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 4px 8px;
|
||||
border-top: 0;
|
||||
word-break: break-all
|
||||
}
|
||||
|
||||
td a {
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:link {
|
||||
color: #088acb
|
||||
}
|
||||
|
||||
thead tr {
|
||||
height: 44px;
|
||||
border-bottom: 1px solid rgba(61, 61, 61, .1)
|
||||
}
|
||||
|
||||
tbody tr:hover {
|
||||
background-color: #e0f3fc
|
||||
}
|
||||
|
||||
tbody tr:first-child:hover {
|
||||
background-color: inherit;
|
||||
}
|
||||
|
||||
tbody tr:first-child td {
|
||||
height: 6px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.fileDate, .fileName, .fileSize {
|
||||
padding-left: 8px
|
||||
}
|
||||
|
||||
.date, .fileDate {
|
||||
width: 25%;
|
||||
line-height: 26px
|
||||
}
|
||||
|
||||
.fileName, .link {
|
||||
width: 55%;
|
||||
line-height: 26px
|
||||
}
|
||||
|
||||
.fileSize, .size {
|
||||
width: 20%;
|
||||
line-height: 26px
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.mirror {
|
||||
width: 100%;
|
||||
padding: 0 15px 10px
|
||||
}
|
||||
|
||||
.mirror, tbody {
|
||||
overflow: auto
|
||||
}
|
||||
|
||||
tr {
|
||||
display: -webkit-box;
|
||||
display: -webkit-flex;
|
||||
display: -ms-flexbox;
|
||||
display: flex
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 4px 8px;
|
||||
border-top: 0;
|
||||
white-space: nowrap;
|
||||
overflow: auto
|
||||
}
|
||||
|
||||
.fileName, .link {
|
||||
min-width: 280px;
|
||||
width: 55%
|
||||
}
|
||||
|
||||
.date, .fileDate {
|
||||
min-width: 190px;
|
||||
width: 25%
|
||||
}
|
||||
|
||||
.fileSize, .size {
|
||||
min-width: 150px;
|
||||
width: 20%
|
||||
}
|
||||
|
||||
.fileSize {
|
||||
margin-right: 10px
|
||||
}
|
||||
|
||||
.fileSize a {
|
||||
display: block;
|
||||
white-space: nowrap
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #ff791a
|
||||
}
|
||||
|
||||
.mirror-nav {
|
||||
padding-left: 15px
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@extends('ie')
|
||||
|
||||
<h1 class="mirror-nav">Download of v{{ $version }}</h1>
|
||||
<div class="mirror">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="fileName">File Name</th>
|
||||
<th class="fileSize">File Size</th>
|
||||
<th class="fileDate">Date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
@forelse($files as $file)
|
||||
<tr>
|
||||
<td class="link"><a href="{{ $file['url'] }}">{{ $file['name'] }}</a></td>
|
||||
<td class="size">{{ $file['size'] }}</td>
|
||||
<td class="date">{{ $file['time'] }}</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td>List is empty</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user