Browse Source

mainbot update

master
filesite 2 weeks ago
parent
commit
317c36972f
  1. 6
      lib/DirScanner.php
  2. 10
      plugins/Common.php
  3. 73
      themes/beauty/controller/CommandController.php

6
lib/DirScanner.php

@ -59,12 +59,12 @@ Class DirScanner { @@ -59,12 +59,12 @@ Class DirScanner {
'm3u8', //视频
);
protected $exifSupportFileExtensions = array(
public $exifSupportFileExtensions = array(
'jpg', //图片
'jpeg', //图片
);
protected $iptcSupportFileExtensions = array(
public $iptcSupportFileExtensions = array(
'jpg', //图片
'jpeg', //图片
);
@ -277,7 +277,7 @@ Class DirScanner { @@ -277,7 +277,7 @@ Class DirScanner {
try {
if (function_exists('exif_read_data')) {
$exif = exif_read_data($realpath, 0, true);
$exif = @exif_read_data($realpath, 0, true);
if(!empty($exif['EXIF']['DateTimeOriginal'])) {
$createTime = strtotime($exif['EXIF']['DateTimeOriginal']);
}

10
plugins/Common.php

@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
* 常用的公用方法
*/
Class Common {
public static $cache = array();
public static function cleanSpecialChars($str) {
if (empty($str)) {return $str;}
@ -783,4 +785,12 @@ Class Common { @@ -783,4 +785,12 @@ Class Common {
return !empty($newArr) ? $newArr : $sorted;
}
public static function setCache($key, $val) {
self::$cache[$key] = $val;
}
public static function getCache($key) {
return !empty(self::$cache[$key]) ? self::$cache[$key] : null;
}
}

73
themes/beauty/controller/CommandController.php

@ -2,6 +2,10 @@ @@ -2,6 +2,10 @@
/**
* Command Controller
*/
require_once __DIR__ . '/../../../lib/DirScanner.php';
require_once __DIR__ . '/../../../plugins/Parsedown.php';
require_once __DIR__ . '/../../../plugins/Common.php';
Class CommandController extends Controller {
public function actionIndex() {
@ -96,16 +100,75 @@ eof; @@ -96,16 +100,75 @@ eof;
//服务器端机器人程序,负责图片、视频文件拍摄时间等信息扫描,并缓存结果供前端使用
public function actionMainBot() {
$thisTime = date('Y-m-d H:i:s');
echo "[MainBot] Main bot started @{$thisTime}\n";
$botLogPrefix = '[MainBot]';
echo "{$botLogPrefix} Main bot started @{$thisTime}\n";
$menus = array(); //菜单,一级目录
$htmlReadme = array(); //Readme.md 内容,底部网站详细介绍
$htmlCateReadme = ''; //当前目录下的Readme.md 内容
$menus_sorted = array(); //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序
$this->scanMediaFiles();
while (true) {
$time = date('Y-m-d H:i:s');
echo "[MainBot] {$time}\n";
//while (true) {
//$time = date('Y-m-d H:i:s');
//echo "{$botLogPrefix} {$time}\n";
//sleep(3);
//}
}
sleep(3);
protected function scanMediaFiles($dirpath = '') {
$rootDir = __DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'];
if (empty($dirpath)) {
$dirpath = $rootDir;
}
echo "\n\n== Scanning directory {$dirpath} ...\n\n";
$scanner = new DirScanner();
$scanner->setWebRoot(FSC::$app['config']['content_directory']);
$scanner->setRootDir($dirpath);
$maxScanDeep = 0; //最大扫描目录级数
$dirTree = $scanner->scan($dirpath, $maxScanDeep);
$scanResults = $scanner->getScanResults();
echo 'Total directories or files: ' . count($scanResults);
echo "\n\n";
$supportedImageExts = FSC::$app['config']['supportedImageExts'];
$supportedVideoExts = FSC::$app['config']['supportedVideoExts'];
$supportedAudioExts = FSC::$app['config']['supportedAudioExts'];
$cacheKey = 'MainBotScanedDirs';
if (!empty($scanResults)) {
foreach ($scanResults as $id => $item) {
$hadScanedDirs = Common::getCache($cacheKey);
if (
!empty($item['filename'])
&& empty($item['original_ctime'])
&& in_array($item['extension'], $supportedImageExts)
&& !in_array($item['extension'], $scanner->exifSupportFileExtensions)
) {
echo "Image file no original_ctime: {$item['filename']}.{$item['extension']}, {$item['realpath']}\n";
}else if (
!empty($item['filename'])
&& empty($item['original_ctime'])
&& (in_array($item['extension'], $supportedVideoExts) || in_array($item['extension'], $supportedAudioExts))
) {
echo "Video or audio file no original_ctime: {$item['filename']}.{$item['extension']}, {$item['realpath']}\n";
}else if (!empty($item['directory']) && empty($hadScanedDirs[$id])) { //if it's directory
$hadScanedDirs[$id] = true;
Common::setCache($cacheKey, $hadScanedDirs);
sleep(1);
$this->scanMediaFiles($item['realpath']);
}
}
}
}
}

Loading…
Cancel
Save