|
|
@ -23,7 +23,7 @@ Class SiteController extends Controller { |
|
|
|
|
|
|
|
|
|
|
|
//优先从缓存读取数据 |
|
|
|
//优先从缓存读取数据 |
|
|
|
$defaultCateId = $scanner->getId(preg_replace("/\/$/", '', realpath($rootDir))); |
|
|
|
$defaultCateId = $scanner->getId(preg_replace("/\/$/", '', realpath($rootDir))); |
|
|
|
$maxScanDeep = 2; //最大扫描目录级数 |
|
|
|
$maxScanDeep = 0; //最大扫描目录级数 |
|
|
|
$cacheKey = $this->getCacheKey($defaultCateId, 'tree', $maxScanDeep); |
|
|
|
$cacheKey = $this->getCacheKey($defaultCateId, 'tree', $maxScanDeep); |
|
|
|
$cachedData = Common::getCacheFromFile($cacheKey); |
|
|
|
$cachedData = Common::getCacheFromFile($cacheKey); |
|
|
|
if (!empty($cachedData)) { |
|
|
|
if (!empty($cachedData)) { |
|
|
@ -45,15 +45,22 @@ Class SiteController extends Controller { |
|
|
|
Common::saveCacheToFile($cacheKey, $scanResults); |
|
|
|
Common::saveCacheToFile($cacheKey, $scanResults); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//优先从缓存获取目录数据 |
|
|
|
//优先从缓存获取目录数据 |
|
|
|
$cacheKey = $this->getCacheKey('all', 'menu', $maxScanDeep); |
|
|
|
$cacheKey = $this->getCacheKey('all', 'menu', $maxScanDeep); |
|
|
|
$menus = Common::getCacheFromFile($cacheKey); |
|
|
|
$menus = Common::getCacheFromFile($cacheKey); |
|
|
|
|
|
|
|
|
|
|
|
if (empty($menus)) { |
|
|
|
if (empty($menus) && !empty($scanResults)) { |
|
|
|
//获取目录 |
|
|
|
//获取目录 |
|
|
|
$menus = $scanner->getMenus(); |
|
|
|
$menus = $scanner->getMenus(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//在path网址中追加cid缓存key参数 |
|
|
|
|
|
|
|
if (!empty($menus)) { |
|
|
|
|
|
|
|
foreach ($menus as $index => $menu) { |
|
|
|
|
|
|
|
$menus[$index]['cid'] = $cacheDataId; |
|
|
|
|
|
|
|
$menus[$index]['path'] .= "&cid={$cacheDataId}"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$titles = array(); |
|
|
|
$titles = array(); |
|
|
|
$readmeFile = $scanner->getDefaultReadme(); |
|
|
|
$readmeFile = $scanner->getDefaultReadme(); |
|
|
|
if (!empty($readmeFile)) { |
|
|
|
if (!empty($readmeFile)) { |
|
|
@ -80,12 +87,8 @@ Class SiteController extends Controller { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//当前目录数据 |
|
|
|
|
|
|
|
$cateId = $this->get('id', $menus[0]['id']); |
|
|
|
|
|
|
|
$subcate = $scanResults[$cateId]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取当前目录下的readme |
|
|
|
//获取当前目录下的readme |
|
|
|
$cateReadmeFile = $scanner->getDefaultReadme($cateId); |
|
|
|
$cateReadmeFile = $scanner->getDefaultReadme($defaultCateId); |
|
|
|
if (!empty($cateReadmeFile)) { |
|
|
|
if (!empty($cateReadmeFile)) { |
|
|
|
$Parsedown = new Parsedown(); |
|
|
|
$Parsedown = new Parsedown(); |
|
|
|
$content = file_get_contents($cateReadmeFile['realpath']); |
|
|
|
$content = file_get_contents($cateReadmeFile['realpath']); |
|
|
@ -93,11 +96,14 @@ Class SiteController extends Controller { |
|
|
|
$htmlCateReadme = $scanner->fixMDUrls($cateReadmeFile['realpath'], $htmlCateReadme); |
|
|
|
$htmlCateReadme = $scanner->fixMDUrls($cateReadmeFile['realpath'], $htmlCateReadme); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//获取默认mp3文件 |
|
|
|
//优先从缓存获取默认mp3文件 |
|
|
|
$rootCateId = $this->get('id', ''); |
|
|
|
$cacheKey = $this->getCacheKey('root', 'mp3', $maxScanDeep); |
|
|
|
$mp3File = $scanner->getDefaultFile('mp3', $rootCateId); |
|
|
|
$mp3File = Common::getCacheFromFile($cacheKey); |
|
|
|
if (empty($mp3File)) { |
|
|
|
if (empty($mp3File)) { |
|
|
|
$mp3File = $scanner->getDefaultFile('mp3'); |
|
|
|
$mp3File = $scanner->getDefaultFile('mp3', $defaultCateId); |
|
|
|
|
|
|
|
if (!empty($mp3File)) { |
|
|
|
|
|
|
|
Common::saveCacheToFile($cacheKey, $mp3File); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -114,13 +120,13 @@ Class SiteController extends Controller { |
|
|
|
} |
|
|
|
} |
|
|
|
$viewName = 'index'; |
|
|
|
$viewName = 'index'; |
|
|
|
$params = compact( |
|
|
|
$params = compact( |
|
|
|
'cateId', 'page', 'pageSize', 'cacheDataId', |
|
|
|
'page', 'pageSize', 'cacheDataId', |
|
|
|
'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme', 'mp3File' |
|
|
|
'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme', 'mp3File' |
|
|
|
); |
|
|
|
); |
|
|
|
return $this->render($viewName, $params, $pageTitle); |
|
|
|
return $this->render($viewName, $params, $pageTitle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//清空缓存 |
|
|
|
//TODO: 清空所有缓存 |
|
|
|
public function actionCleancache() { |
|
|
|
public function actionCleancache() { |
|
|
|
$prefix = FSC::$app['config']['theme']; |
|
|
|
$prefix = FSC::$app['config']['theme']; |
|
|
|
$cacheKey = "{$prefix}_allFilesTree"; |
|
|
|
$cacheKey = "{$prefix}_allFilesTree"; |
|
|
@ -134,4 +140,35 @@ Class SiteController extends Controller { |
|
|
|
return $this->renderJson(compact('code', 'msg')); |
|
|
|
return $this->renderJson(compact('code', 'msg')); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//根据目录id,获取第一张图网址作为封面图返回 |
|
|
|
|
|
|
|
public function actionDirsnap() { |
|
|
|
|
|
|
|
$code = 1; |
|
|
|
|
|
|
|
$msg = 'OK'; |
|
|
|
|
|
|
|
$url = ''; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$cacheId = $this->post('cid', ''); |
|
|
|
|
|
|
|
$cateId = $this->post('id', ''); |
|
|
|
|
|
|
|
if (empty($cacheId) || empty($cateId)) { |
|
|
|
|
|
|
|
$code = 0; |
|
|
|
|
|
|
|
$msg = '参数不能为空'; |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
//从缓存数据中获取目录的realpath |
|
|
|
|
|
|
|
$cachedData = Common::getCacheFromFile($cacheId); |
|
|
|
|
|
|
|
if (!empty($cachedData)) { |
|
|
|
|
|
|
|
$realpath = $cachedData[$cateId]['realpath']; |
|
|
|
|
|
|
|
$scanner = new DirScanner(); |
|
|
|
|
|
|
|
$scanner->setWebRoot($this->getCurrentWebroot($realpath)); |
|
|
|
|
|
|
|
$scanner->setRootDir($realpath); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$imgExts = !empty(FSC::$app['config']['supportedImageExts']) ? FSC::$app['config']['supportedImageExts'] : array('jpg', 'jpeg', 'png', 'webp', 'gif'); |
|
|
|
|
|
|
|
$url = $scanner->getSnapshotImage($realpath, $imgExts); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
$code = 0; |
|
|
|
|
|
|
|
$msg = '缓存数据已失效,请刷新网页'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->renderJson(compact('code', 'msg', 'url')); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|