Browse Source

file counter update

master
filesite 1 month ago
parent
commit
39cce6cac9
  1. 59
      themes/beauty/controller/CommandController.php
  2. 9
      themes/beauty/controller/ListController.php
  3. 5
      themes/beauty/controller/SiteController.php
  4. 6
      themes/beauty/views/list/bydate.php
  5. 6
      themes/beauty/views/site/index.php

59
themes/beauty/controller/CommandController.php

@ -172,12 +172,15 @@ eof; @@ -172,12 +172,15 @@ eof;
$maxScanDeep = 0; //最大扫描目录级数
$dirTree = $scanner->scan($dirpath, $maxScanDeep);
$this->updateAllDirTreeCache($dirTree);
$scanResults = $scanner->getScanResults();
echo 'Total directories or files: ' . count($scanResults);
echo "\n";
//统计文件数量
$dirId = $scanner->getId($dirpath);
$this->updateAllDirTreeCache($dirId, $scanResults);
$supportedImageExts = FSC::$app['config']['supportedImageExts'];
$supportedVideoExts = FSC::$app['config']['supportedVideoExts'];
$supportedAudioExts = FSC::$app['config']['supportedAudioExts'];
@ -409,7 +412,7 @@ eof; @@ -409,7 +412,7 @@ eof;
return true;
}
protected function updateAllDirTreeCache($dirTree) {
protected function updateAllDirTreeCache($dirId, $dirTree) {
$cacheKey = $this->allDirTreeCacheKey;
$cacheData = Common::getCache($cacheKey);
if (empty($cacheData)) {
@ -417,52 +420,64 @@ eof; @@ -417,52 +420,64 @@ eof;
}
$cacheData = array_merge($cacheData, $dirTree);
$pid = '';
$imgNum = $videoNum = $audioNum = 0;
if (empty($cacheData[$dirId])) {
$cacheData[$dirId] = $dirTree;
}
$supportedImageExts = FSC::$app['config']['supportedImageExts'];
$supportedVideoExts = FSC::$app['config']['supportedVideoExts'];
$supportedAudioExts = FSC::$app['config']['supportedAudioExts'];
$imgNum = $videoNum = $audioNum = 0;
foreach ($dirTree as $id => $item) {
if (empty($item['pid'])) {
break;
echo "Ignored file no pid: {$id}\n";
print_r($item);
echo "\n";
continue;
}
//TODO: 递归更新所有父目录
$pid = $item['pid'];
if (!isset($cacheData[$pid]['image_total'])) {
$cacheData[$pid]['image_total'] = 0;
}
if (!isset($cacheData[$pid]['video_total'])) {
$cacheData[$pid]['video_total'] = 0;
}
if (!isset($cacheData[$pid]['audio_total'])) {
$cacheData[$pid]['audio_total'] = 0;
}
if (
!empty($item['filename']) && in_array($item['extension'], $supportedImageExts)
) {
$cacheData[$pid]['image_total'] ++;
$imgNum ++;
}else if (
!empty($item['filename']) && in_array($item['extension'], $supportedVideoExts)
) {
$cacheData[$pid]['video_total'] ++;
$videoNum ++;
}else if (
!empty($item['filename']) && in_array($item['extension'], $supportedAudioExts)
) {
$cacheData[$pid]['audio_total'] ++;
$audioNum ++;
}
}
if (!empty($pid) && !empty($cacheData[$pid])) {
if (!isset($cacheData[$pid]['image_total'])) {
$cacheData[$pid]['image_total'] = 0;
}
if (!isset($cacheData[$pid]['video_total'])) {
$cacheData[$pid]['video_total'] = 0;
}
if (!isset($cacheData[$pid]['audio_total'])) {
$cacheData[$pid]['audio_total'] = 0;
}
$cacheData[$pid]['image_total'] += $imgNum;
$cacheData[$pid]['video_total'] += $videoNum;
$cacheData[$pid]['audio_total'] += $audioNum;
}
$cacheData[$dirId]['image_total'] = $imgNum;
$cacheData[$dirId]['video_total'] = $videoNum;
$cacheData[$dirId]['audio_total'] = $audioNum;
echo "File total: {$dirId}: image {$imgNum}, video {$videoNum}, audio {$audioNum}\n";
return Common::setCache($cacheKey, $cacheData);
}
protected function getAllFilesTotalInSubDirs() {
}
//汇总每个目录下图片、视频、音乐文件数量
/**
* 数据格式:
@ -477,7 +492,7 @@ eof; @@ -477,7 +492,7 @@ eof;
$dirCounter = array();
foreach ($cacheData as $id => $item) {
if ( !empty($item['directory']) && isset($item['image_total']) ) {
if ( isset($item['image_total']) ) {
$dirCounter[$id] = array(
'image_total' => $item['image_total'],
'video_total' => $item['video_total'],

9
themes/beauty/controller/ListController.php

@ -10,6 +10,7 @@ require_once __DIR__ . '/../../../plugins/Html.php'; @@ -10,6 +10,7 @@ require_once __DIR__ . '/../../../plugins/Html.php';
Class ListController extends Controller {
protected $dateIndexCacheKey = 'MainBotDateIndex'; //索引数据的key单独缓存,缓存key为此{cacheKey}_keys
protected $allFilesCacheKey = 'MainBotAllFiles';
protected $dirCounterCacheKey = 'MainBotDirCounter'; //缓存所有目录包含的文件数量
protected $noOriginalCtimeFilesCacheKey = 'MainBotNoOriginalCtimeFiles';
public function actionIndex() {
@ -304,12 +305,14 @@ Class ListController extends Controller { @@ -304,12 +305,14 @@ Class ListController extends Controller {
//从缓存文件获取按年份、月份归类的索引数据
$cacheDataByDate = Common::getCacheFromFile($this->dateIndexCacheKey . '_keys', 86400*365, 'index');
//从缓存文件获取所有目录文件数量数据
$dirCounters = Common::getCacheFromFile($this->dirCounterCacheKey, 86400*365, 'index');
$viewName = '//site/index'; //共享视图
$params = compact(
'cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'breadcrumbs', 'htmlCateReadme',
'mp3File', 'page', 'pageSize', 'cacheDataId', 'copyright', 'showType', 'isAdminIp', 'allFiles',
'cacheDataByDate'
'cacheDataByDate', 'dirCounters'
);
return $this->render($viewName, $params, $pageTitle);
}
@ -606,6 +609,8 @@ Class ListController extends Controller { @@ -606,6 +609,8 @@ Class ListController extends Controller {
return $this->renderJson(compact('page', 'pageSize', 'audios'));
}
//从缓存文件获取所有目录文件数量数据
$dirCounters = Common::getCacheFromFile($this->dirCounterCacheKey, 86400*365, 'index');
$pageTitlePrefix = "{$intYear}年的";
if (!empty($para_month)) {
@ -622,7 +627,7 @@ Class ListController extends Controller { @@ -622,7 +627,7 @@ Class ListController extends Controller {
'allFiles',
'cacheData',
'cacheData_keys', 'monthsByType',
'para_year', 'para_month'
'para_year', 'para_month', 'dirCounters'
);
return $this->render($viewName, $params, $pageTitle);
}

5
themes/beauty/controller/SiteController.php

@ -10,6 +10,7 @@ require_once __DIR__ . '/../../../plugins/Html.php'; @@ -10,6 +10,7 @@ require_once __DIR__ . '/../../../plugins/Html.php';
Class SiteController extends Controller {
protected $dateIndexCacheKey = 'MainBotDateIndex'; //索引数据的key单独缓存,缓存key为此{cacheKey}_keys
protected $allFilesCacheKey = 'MainBotAllFiles';
protected $dirCounterCacheKey = 'MainBotDirCounter'; //缓存所有目录包含的文件数量
protected $noOriginalCtimeFilesCacheKey = 'MainBotNoOriginalCtimeFiles';
public function actionIndex() {
@ -263,13 +264,15 @@ Class SiteController extends Controller { @@ -263,13 +264,15 @@ Class SiteController extends Controller {
//从缓存文件获取按年份、月份归类的索引数据
$cacheDataByDate = Common::getCacheFromFile($this->dateIndexCacheKey . '_keys', 86400*365, 'index');
//从缓存文件获取所有目录文件数量数据
$dirCounters = Common::getCacheFromFile($this->dirCounterCacheKey, 86400*365, 'index');
$viewName = 'index';
$params = compact(
'page', 'pageSize', 'cacheDataId', 'showType',
'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme', 'mp3File', 'copyright',
'alertWarning', 'isAdminIp', 'allFiles',
'cacheDataByDate'
'cacheDataByDate', 'dirCounters'
);
return $this->render($viewName, $params, $pageTitle);
}

6
themes/beauty/views/list/bydate.php

@ -86,10 +86,16 @@ eof; @@ -86,10 +86,16 @@ eof;
<?php
if (!empty($viewData['menus'])) { //只显示第一级目录
foreach ($viewData['menus'] as $index => $item) {
$fileTotal = 0;
if ( !empty($viewData['dirCounters']) && !empty($viewData['dirCounters'][$item['id']]) ) {
$dirTotal = $viewData['dirCounters'][$item['id']];
$fileTotal = $dirTotal['image_total'] + $dirTotal['video_total'] + $dirTotal['audio_total'];
}
echo <<<eof
<li><a href="{$item['path']}">
<img src="/img/beauty/folder.svg" alt="directories" width="17" class="menu-icon">
{$item['directory']}
<small class="badge">{$fileTotal}</small>
</a></li>
eof;
}

6
themes/beauty/views/site/index.php

@ -97,11 +97,17 @@ eof; @@ -97,11 +97,17 @@ eof;
$breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : [];
if (!empty($viewData['menus'])) { //只显示第一级目录
foreach ($viewData['menus'] as $index => $item) {
$fileTotal = 0;
if ( !empty($viewData['dirCounters']) && !empty($viewData['dirCounters'][$item['id']]) ) {
$dirTotal = $viewData['dirCounters'][$item['id']];
$fileTotal = $dirTotal['image_total'] + $dirTotal['video_total'] + $dirTotal['audio_total'];
}
$selected = $item['id'] == $selectedId || (!empty($breadcrumbs) && $item['id'] == $breadcrumbs[0]['id']) ? 'active' : '';
echo <<<eof
<li class="{$selected}"><a href="{$item['path']}">
<img src="/img/beauty/folder.svg" alt="directories" width="17" class="menu-icon">
{$item['directory']}
<small class="badge">{$fileTotal}</small>
</a></li>
eof;
}

Loading…
Cancel
Save