diff --git a/lib/DirScanner.php b/lib/DirScanner.php index 6d492dd..54b224b 100644 --- a/lib/DirScanner.php +++ b/lib/DirScanner.php @@ -815,22 +815,19 @@ Class DirScanner { RecursiveIteratorIterator::SELF_FIRST ); - $imgUrl = ''; + $imgData = null; foreach ($iterator as $item) { if ($item->isFile()) { $extension = $item->getExtension(); if (in_array(strtolower($extension), $imgExts)) { $imgPath = $item->getPath() . '/' . $item->getFilename(); $imgData = $this->getFileData($imgPath); - if (!empty($imgData['path'])) { - $imgUrl = $imgData['path']; - } break; } } } - return $imgUrl; + return $imgData; } } diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php index 1cdbd7d..609cd15 100644 --- a/themes/beauty/controller/SiteController.php +++ b/themes/beauty/controller/SiteController.php @@ -187,15 +187,27 @@ Class SiteController extends Controller { $scanner->setRootDir($realpath); $imgExts = !empty(FSC::$app['config']['supportedImageExts']) ? FSC::$app['config']['supportedImageExts'] : array('jpg', 'jpeg', 'png', 'webp', 'gif'); - $url = $scanner->getSnapshotImage($realpath, $imgExts); + $imgFile = $scanner->getSnapshotImage($realpath, $imgExts); + //支持视频目录 - if (empty($url)) { + if (empty($imgFile)) { $videoExts = !empty(FSC::$app['config']['supportedVideoExts']) ? FSC::$app['config']['supportedVideoExts'] : array('mp4', 'mov', 'm3u8'); - $firstVideoPath = $scanner->getSnapshotImage($realpath, $videoExts); - if (!empty($firstVideoPath)) { + $firstVideo = $scanner->getSnapshotImage($realpath, $videoExts); + if (!empty($firstVideo)) { $url = '/img/beauty/video_dir.png'; + + //尝试从缓存数据中获取封面图 + $cacheKey = $firstVideo['id']; + $expireSeconds = 86400*30; //有效期30天 + $cacheSubDir = 'video'; + $cachedData = Common::getCacheFromFile($cacheKey, $expireSeconds, $cacheSubDir); + if (!empty($cachedData)) { + $url = $cachedData['snapshot']; + } } + }else { + $url = $imgFile['path']; } }else { $code = 0;