diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index c1d494a..5016b0d 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -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 diff --git a/themes/beauty/controller/CommandController.php b/themes/beauty/controller/CommandController.php index 2a37be1..3fa1317 100644 --- a/themes/beauty/controller/CommandController.php +++ b/themes/beauty/controller/CommandController.php @@ -117,30 +117,43 @@ eof; echo "{$botLogPrefix} Main bot started @{$thisTime}\n"; - $menus = array(); //菜单,一级目录 - $htmlReadme = array(); //Readme.md 内容,底部网站详细介绍 - $htmlCateReadme = ''; //当前目录下的Readme.md 内容 - $menus_sorted = array(); //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序 - - - //执行一次扫描任务 - $this->cleanScanCaches(); - $this->scanMediaFiles(); - $this->saveDateIndexIntoCacheFile(); - $this->saveNoOriginalCtimeFilesIntoFile(); - //缓存所有文件id跟文件信息,便于根据id列表来渲染,并按id首字母分子目录存放,以支持大量文件的场景 - $this->saveAllFilesIntoCacheFile(); - //缓存所有目录的文件数量 - $this->saveDirCounter(); - - //按年、月保存文件数据,以便按年、月显示 - - //while (true) { - //$time = date('Y-m-d H:i:s'); - //echo "{$botLogPrefix} {$time}\n"; - - //sleep(3); - //} + //$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(); + $this->saveDateIndexIntoCacheFile(); + $this->saveNoOriginalCtimeFilesIntoFile(); + //缓存所有文件id跟文件信息,便于根据id列表来渲染,并按id首字母分子目录存放,以支持大量文件的场景 + $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(); + } + } + + sleep(10); + } } //清空内存中的临时缓存数据 @@ -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)) { diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php index c732aec..00b4ffd 100644 --- a/themes/beauty/controller/SiteController.php +++ b/themes/beauty/controller/SiteController.php @@ -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')); + } + } diff --git a/www/css/beauty.css b/www/css/beauty.css index 6df2221..29d81c4 100644 --- a/www/css/beauty.css +++ b/www/css/beauty.css @@ -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{