mirror of
https://github.com/ledccn/IYUUPlus.git
synced 2024-09-20 07:05:28 +00:00
fix add:一键清理辅种缓存、一键清理转移缓存、任务热刷新
This commit is contained in:
parent
edc4984ec3
commit
e13b84b51a
|
@ -147,7 +147,7 @@ class Api extends BaseController
|
|||
}
|
||||
|
||||
/**
|
||||
* 清理缓存
|
||||
* 清理系统级别的缓存、日志
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
|
|
|
@ -8,7 +8,6 @@ use app\common\Config as Conf;
|
|||
use app\common\Constant;
|
||||
use app\domain\Config;
|
||||
use app\domain\Crontab;
|
||||
use app\domain\Reseed;
|
||||
/**
|
||||
* Class Status
|
||||
* @package app\controller
|
||||
|
@ -49,21 +48,20 @@ class Status extends BaseController
|
|||
$system_info = sprintf('%s / %s', PHP_OS, PHP_OS_FAMILY);
|
||||
//读取git信息
|
||||
$updated_at = get_current_git_filemtime() . (get_current_git_commit() ? ' (' . get_current_git_commit() . ')' : '');
|
||||
$str = '<a href="https://github.com/ledccn/IYUUPlus/commits/master" target="_blank">%s</a>';
|
||||
$updated_at = sprintf($str, strlen($updated_at) > 10 ? $updated_at : '点此查看');
|
||||
$updated_at = strlen($updated_at) > 10 ? $updated_at : '点此查看';
|
||||
|
||||
$rs['data'] = [
|
||||
'cron_total' => count($cron),
|
||||
'sites_total'=> count($user_sites),
|
||||
'sites_conut'=> count($sites),
|
||||
'cron_total' => count($cron),
|
||||
'sites_total' => count($user_sites),
|
||||
'sites_conut' => count($sites),
|
||||
'clients_total' => count($clients),
|
||||
'project' => iyuu_name(),
|
||||
'version' => $version,
|
||||
'updated_at' => $updated_at,
|
||||
'system_info' => $system_info,
|
||||
'PHP_VERSION' => PHP_VERSION,
|
||||
'PHP_BINARY' => PHP_BINARY,
|
||||
'RUNTIME_PATH' => runtime_path(),
|
||||
'project' => iyuu_name(),
|
||||
'version' => $version,
|
||||
'updated_at' => $updated_at,
|
||||
'system_info' => $system_info,
|
||||
'PHP_VERSION' => PHP_VERSION,
|
||||
'PHP_BINARY' => PHP_BINARY,
|
||||
'RUNTIME_PATH' => runtime_path(),
|
||||
];
|
||||
return json($rs);
|
||||
}
|
||||
|
|
|
@ -99,13 +99,51 @@ class Task extends BaseController
|
|||
}
|
||||
|
||||
/**
|
||||
* 调试接口
|
||||
* 清理任务缓存
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function test(Request $request): Response
|
||||
public function clearCache(Request $request): Response
|
||||
{
|
||||
$rs = self::RS;
|
||||
$ret = false;
|
||||
|
||||
$clear_type = $request->get('type');
|
||||
switch ($clear_type) {
|
||||
case 'clearReseedCache':
|
||||
$ret = domainReseed::clearReseedCache();
|
||||
break;
|
||||
case 'clearMoveCache':
|
||||
$ret = domainReseed::clearMoveCache();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$rs['data'] = [
|
||||
'success' => $ret
|
||||
];
|
||||
return json($rs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新所有任务
|
||||
* @descr 不同平台的配置,会造成command错误,需要重新解析命令
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function refresh(Request $request): Response
|
||||
{
|
||||
$rs = self::RS;
|
||||
$ret = true;
|
||||
try {
|
||||
Crontab::onWorkerStart();
|
||||
} catch (\Exception $exception) {
|
||||
$ret = false;
|
||||
}
|
||||
$rs['data'] = [
|
||||
'success' => $ret
|
||||
];
|
||||
return json($rs);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ namespace app\domain;
|
|||
|
||||
use app\common\Config as Conf;
|
||||
use app\common\Constant;
|
||||
use IYUU\Library\IFile;
|
||||
|
||||
/**
|
||||
* 辅种相关
|
||||
* Class Reseed
|
||||
|
@ -57,4 +59,42 @@ class Reseed
|
|||
|
||||
return $rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取辅种缓存的存放路径
|
||||
* @return string
|
||||
*/
|
||||
public static function getReseedCachePath():string
|
||||
{
|
||||
return runtime_path() . DIRECTORY_SEPARATOR . 'torrent' . DIRECTORY_SEPARATOR . 'cachehash';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取转移缓存的存放路径
|
||||
* @return string
|
||||
*/
|
||||
public static function getMoveCachePath():string
|
||||
{
|
||||
return runtime_path() . DIRECTORY_SEPARATOR . 'torrent' . DIRECTORY_SEPARATOR . 'cachemove';
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理辅种缓存
|
||||
* @return bool
|
||||
*/
|
||||
public static function clearReseedCache():bool
|
||||
{
|
||||
$dir = self::getReseedCachePath();
|
||||
return IFile::rmdir($dir, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理转移缓存
|
||||
* @return bool
|
||||
*/
|
||||
public static function clearMoveCache():bool
|
||||
{
|
||||
$dir = self::getMoveCachePath();
|
||||
return IFile::rmdir($dir, true);
|
||||
}
|
||||
}
|
||||
|
|
2
init.php
2
init.php
|
@ -30,9 +30,7 @@ echo microtime(true).' composer依赖载入完成!'.PHP_EOL;
|
|||
|
||||
// 定义目录
|
||||
defined('ROOT_PATH') or define('ROOT_PATH', __DIR__);
|
||||
defined('DB_PATH') or define('DB_PATH', __DIR__ . DIRECTORY_SEPARATOR . 'db');
|
||||
defined('RUNTIME_PATH') or define('RUNTIME_PATH', __DIR__ . DIRECTORY_SEPARATOR . 'runtime');
|
||||
defined('CRONATB_PATH') or define('CRONATB_PATH', RUNTIME_PATH . DIRECTORY_SEPARATOR . 'crontab');
|
||||
defined('TORRENT_PATH') or define('TORRENT_PATH', RUNTIME_PATH . DIRECTORY_SEPARATOR . 'torrent');
|
||||
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
|
||||
|
||||
|
|
|
@ -167,6 +167,15 @@
|
|||
{{# } }}
|
||||
</script>
|
||||
|
||||
<!-- 模板:表格头工具栏 -->
|
||||
<script type="text/html" id="tableTopToolbar">
|
||||
<div class="layui-btn-container">
|
||||
<button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="clearReseedCache">清理辅种缓存</button>
|
||||
<button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="clearMoveCache">清理转移缓存</button>
|
||||
<button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="refreshCrontab">刷新任务</button>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<!-- 模板:表格行工具条 -->
|
||||
<script type="text/html" id="tableToolbar">
|
||||
<span class="layui-badge layui-bg-cyan" lay-event="run">运行</span>
|
||||
|
@ -301,6 +310,12 @@
|
|||
table.render({
|
||||
elem: '#tableId'
|
||||
,url: API.tableList
|
||||
,toolbar: '#tableTopToolbar'
|
||||
,defaultToolbar: ['filter', 'print', {
|
||||
title: '提示'
|
||||
,layEvent: 'LAYTABLE_TIPS'
|
||||
,icon: 'layui-icon-tips'
|
||||
}]
|
||||
,parseData: function(res){
|
||||
return {
|
||||
"code": res.ret === 200 ? 0 : res.ret,
|
||||
|
@ -379,6 +394,38 @@
|
|||
,limit:500
|
||||
});
|
||||
|
||||
/**
|
||||
* 监听:头工具栏事件
|
||||
*/
|
||||
table.on('toolbar(tableFilter)', function(obj){
|
||||
let checkStatus = table.checkStatus(obj.config.id);
|
||||
let data = checkStatus.data;
|
||||
switch(obj.event){
|
||||
case 'clearReseedCache':
|
||||
case 'clearMoveCache':
|
||||
$.getJSON('/Task/clearCache', {'type': obj.event}, function (d) {
|
||||
if (d.ret === 200) {
|
||||
layer.msg(d.data.success ? '清理成功' : '清理失败');
|
||||
return;
|
||||
}
|
||||
layer.msg('接口请求失败:/Task/clearCache');
|
||||
});
|
||||
break;
|
||||
case 'refreshCrontab':
|
||||
$.getJSON('/Task/refresh', function (d) {
|
||||
if (d.ret === 200) {
|
||||
layer.msg(d.data.success ? '全部任务刷新成功' : '任务刷新失败');
|
||||
return;
|
||||
}
|
||||
layer.msg('接口请求失败:/Task/refresh');
|
||||
});
|
||||
break;
|
||||
case 'LAYTABLE_TIPS':
|
||||
layer.alert('这是工具栏右侧自定义的一个图标按钮');
|
||||
break;
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* 监听:行工具条
|
||||
*/
|
||||
|
|
|
@ -207,7 +207,7 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td>最后更新</td>
|
||||
<td id="updated_at"></td>
|
||||
<td><a href="https://github.com/ledccn/IYUUPlus/commits/master" target="_blank" id="updated_at"></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>系统环境</td>
|
||||
|
|
|
@ -60,6 +60,7 @@ class IFile
|
|||
|
||||
/**
|
||||
* @brief 清空目录下的所有文件
|
||||
* @param string $dir
|
||||
* @return bool false:失败; true:成功;
|
||||
*/
|
||||
public static function clearDir($dir)
|
||||
|
|
Loading…
Reference in New Issue
Block a user