Browse Source

add api to start mainbot scan

master
filesite 1 month ago
parent
commit
44c2058ee9
  1. 3
      docker-entrypoint.sh
  2. 38
      themes/beauty/controller/CommandController.php
  3. 25
      themes/beauty/controller/SiteController.php
  4. 2
      www/css/beauty.css

3
docker-entrypoint.sh

@ -33,6 +33,9 @@ fi @@ -33,6 +33,9 @@ fi
if [ -e /usr/local/bin/php ]; then
echo "Start main bot."
cd /var/www/machete/
if [ -f runtime/cache/stats_scan.json ]; then
rm -f runtime/cache/stats_scan.json
fi
/usr/local/bin/php bin/command.php mainBot &
fi

38
themes/beauty/controller/CommandController.php

@ -117,12 +117,17 @@ eof; @@ -117,12 +117,17 @@ eof;
echo "{$botLogPrefix} Main bot started @{$thisTime}\n";
$menus = array(); //菜单,一级目录
$htmlReadme = array(); //Readme.md 内容,底部网站详细介绍
$htmlCateReadme = ''; //当前目录下的Readme.md 内容
$menus_sorted = array(); //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序
//$menus = array(); //菜单,一级目录
//$htmlReadme = array(); //Readme.md 内容,底部网站详细介绍
//$htmlCateReadme = ''; //当前目录下的Readme.md 内容
//$menus_sorted = array(); //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序
while (true) {
$time = date('Y-m-d H:i:s');
echo "{$botLogPrefix} {$time}\n";
$statsFile = __DIR__ . '/../../../runtime/cache/stats_scan.json';
if (!file_exists($statsFile)) {
//执行一次扫描任务
$this->cleanScanCaches();
$this->scanMediaFiles();
@ -132,15 +137,23 @@ eof; @@ -132,15 +137,23 @@ eof;
$this->saveAllFilesIntoCacheFile();
//缓存所有目录的文件数量
$this->saveDirCounter();
}else {
try {
$json = file_get_contents($statsFile);
$stats = json_decode($json, true);
if ($stats['status'] == 'running') {
echo "{$botLogPrefix} It's already running...\n";
}else {
$date = date('Y-m-d H:i:s', $stats['updatetime']);
echo "{$botLogPrefix} It's finished at {$date}.\n";
}
}catch(Exception $e) {
echo "{$botLogPrefix} Exception: " . $e->getMessage();
}
}
//按年、月保存文件数据,以便按年、月显示
//while (true) {
//$time = date('Y-m-d H:i:s');
//echo "{$botLogPrefix} {$time}\n";
//sleep(3);
//}
sleep(10);
}
}
//清空内存中的临时缓存数据
@ -294,6 +307,7 @@ eof; @@ -294,6 +307,7 @@ eof;
//保存进度文件
file_put_contents($statsFile, json_encode($stats) . "\n");
chmod($statsFile, 0777);
}else if (file_exists($statsFile)) { //更新当前扫描目录
$json = file_get_contents($statsFile);
if (!empty($json)) {

25
themes/beauty/controller/SiteController.php

@ -1086,4 +1086,29 @@ Class SiteController extends Controller { @@ -1086,4 +1086,29 @@ Class SiteController extends Controller {
return $this->renderJson(compact('code', 'percent', 'msg'));
}
//启动MainBot扫描
public function actionStartbot() {
$code = 0;
$msg = 'Fail';
$statsFile = __DIR__ . '/../../../runtime/cache/stats_scan.json';
if (file_exists($statsFile)) {
try {
$json = file_get_contents($statsFile);
$stats = json_decode($json, true);
if (!empty($stats['status']) && $stats['status'] == 'finished') {
unlink($statsFile);
$code = 1;
$msg = '文件扫描即将开始';
}else {
$msg = "文件扫描任务还在执行中,请刷新网页查看进度";
}
}catch(Exception $e) {
$msg = '文件扫描任务启动失败:' . $e->getMessage();
}
}
return $this->renderJson(compact('code', 'msg'));
}
}

2
www/css/beauty.css

@ -173,7 +173,7 @@ a:link{text-decoration:none} @@ -173,7 +173,7 @@ a:link{text-decoration:none}
.simple-form{max-width:480px;margin:0 auto}
.botstats{margin-bottom:2px;margin-left:10px;margin-right:10px}
.botstats{margin-bottom:1px;margin-left:15px;margin-right:15px}
/*自动播放图片时隐藏标题*/
.fancybox__container{

Loading…
Cancel
Save