From 8e64f3931920d8d67c51d9bb8ad293fe6a1d0dd4 Mon Sep 17 00:00:00 2001 From: filesite Date: Tue, 23 Jul 2024 16:46:50 +0800 Subject: [PATCH] add dataType support --- themes/beauty/controller/ListController.php | 46 +++++++++++++++++++++ themes/beauty/controller/SiteController.php | 45 ++++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/themes/beauty/controller/ListController.php b/themes/beauty/controller/ListController.php index ed2af9c..6214c0d 100644 --- a/themes/beauty/controller/ListController.php +++ b/themes/beauty/controller/ListController.php @@ -135,6 +135,52 @@ Class ListController extends Controller { $pageTitle = $readmeFile['title']; } + + //dataType支持:[image, video] + $dataType = $this->get('dataType', 'html'); + if ($dataType == 'image') { + $imgExts = !empty(FSC::$app['config']['supportedImageExts']) ? FSC::$app['config']['supportedImageExts'] : array('jpg', 'jpeg', 'png', 'webp', 'gif'); + $imgs = array(); + $pageStartIndex = ($page-1) * $pageSize; + $index = 0; + foreach ($subcate['files'] as $id => $item) { + //翻页支持 + if ($index < $pageStartIndex) { + $index ++; + continue; + }else if ($index >= $pageStartIndex + $pageSize) { + break; + } + + if (in_array($item['extension'], $imgExts)) { + array_push($imgs, $item); + $index ++; + } + } + return $this->renderJson(compact('page', 'pageSize', 'imgs')); + }else if ($dataType == 'video') { + $videoExts = !empty(FSC::$app['config']['supportedVideoExts']) ? FSC::$app['config']['supportedVideoExts'] : array('mp4', 'mov', 'm3u8'); + $videos = array(); + $pageStartIndex = ($page-1) * $pageSize; + $index = 0; + foreach ($subcate['files'] as $id => $item) { + //翻页支持 + if ($index < $pageStartIndex) { + $index ++; + continue; + }else if ($index >= $pageStartIndex + $pageSize) { + break; + } + + if (in_array($item['extension'], $videoExts)) { + array_push($videos, $item); + $index ++; + } + } + return $this->renderJson(compact('page', 'pageSize', 'videos')); + } + + $viewName = '//site/index'; //共享视图 $params = compact( 'cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'breadcrumbs', 'htmlCateReadme', diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php index fda45ea..09b9274 100644 --- a/themes/beauty/controller/SiteController.php +++ b/themes/beauty/controller/SiteController.php @@ -137,6 +137,51 @@ Class SiteController extends Controller { $copyright = $readmeFile['copyright']; } + //dataType支持:[image, video] + $dataType = $this->get('dataType', 'html'); + if ($dataType == 'image') { + $imgExts = !empty(FSC::$app['config']['supportedImageExts']) ? FSC::$app['config']['supportedImageExts'] : array('jpg', 'jpeg', 'png', 'webp', 'gif'); + $imgs = array(); + $pageStartIndex = ($page-1) * $pageSize; + $index = 0; + foreach ($scanResults as $id => $item) { + //翻页支持 + if ($index < $pageStartIndex) { + $index ++; + continue; + }else if ($index >= $pageStartIndex + $pageSize) { + break; + } + + if (in_array($item['extension'], $imgExts)) { + array_push($imgs, $item); + $index ++; + } + } + return $this->renderJson(compact('page', 'pageSize', 'imgs')); + }else if ($dataType == 'video') { + $videoExts = !empty(FSC::$app['config']['supportedVideoExts']) ? FSC::$app['config']['supportedVideoExts'] : array('mp4', 'mov', 'm3u8'); + $videos = array(); + $pageStartIndex = ($page-1) * $pageSize; + $index = 0; + foreach ($scanResults as $id => $item) { + //翻页支持 + if ($index < $pageStartIndex) { + $index ++; + continue; + }else if ($index >= $pageStartIndex + $pageSize) { + break; + } + + if (in_array($item['extension'], $videoExts)) { + array_push($videos, $item); + $index ++; + } + } + return $this->renderJson(compact('page', 'pageSize', 'videos')); + } + + $viewName = 'index'; $params = compact( 'page', 'pageSize', 'cacheDataId',