From d47e5345b91f6111412489f993d19473f465ed8d Mon Sep 17 00:00:00 2001 From: filesite Date: Wed, 17 Jul 2024 09:55:48 +0800 Subject: [PATCH] add small image create for new dirs --- themes/beauty/controller/SiteController.php | 16 +++++++++++----- www/js/beauty.js | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php index 1b44fec..92835e8 100644 --- a/themes/beauty/controller/SiteController.php +++ b/themes/beauty/controller/SiteController.php @@ -171,6 +171,7 @@ Class SiteController extends Controller { $code = 1; $msg = 'OK'; $url = ''; + $img_id = ''; $cacheId = $this->post('cid', ''); $cateId = $this->post('id', ''); @@ -180,9 +181,9 @@ Class SiteController extends Controller { }else { //优先从缓存获取 $cacheKey = $this->getCacheKey($cateId, 'dirsnap'); - $url = Common::getCacheFromFile($cacheKey); + $cachedData = Common::getCacheFromFile($cacheKey); - if (empty($url)) { + if (empty($cachedData)) { //从缓存数据中获取目录的realpath $cachedData = Common::getCacheFromFile($cacheId); if (!empty($cachedData)) { @@ -208,11 +209,12 @@ Class SiteController extends Controller { $cachedData = Common::getCacheFromFile($cacheKey_snap, $expireSeconds, $cacheSubDir); if (!empty($cachedData)) { $url = $cachedData['snapshot']; - Common::saveCacheToFile($cacheKey, $url); + Common::saveCacheToFile($cacheKey, compact('url', 'img_id')); } } }else { $url = $imgFile['path']; + $img_id = $imgFile['id']; //小尺寸图片支持 $cacheKey = $this->getCacheKey($imgFile['id'], 'imgsm'); @@ -221,18 +223,22 @@ Class SiteController extends Controller { $cachedData = Common::getCacheFromFile($cacheKey, $expireSeconds, $cacheSubDir); if (!empty($cachedData)) { $url = $cachedData; + $img_id = ''; //无需再次生成小尺寸图片 } - Common::saveCacheToFile($cacheKey, $url); + Common::saveCacheToFile($cacheKey, compact('url', 'img_id')); } }else { $code = 0; $msg = '缓存数据已失效,请刷新网页'; } + }else { + $url = $cachedData['url']; + $img_id = $cachedData['img_id']; } } - return $this->renderJson(compact('code', 'msg', 'url')); + return $this->renderJson(compact('code', 'msg', 'url', 'img_id')); } //优先从缓存获取小尺寸的图片 diff --git a/www/js/beauty.js b/www/js/beauty.js index 0fd2363..a7c1607 100644 --- a/www/js/beauty.js +++ b/www/js/beauty.js @@ -180,7 +180,21 @@ $('.dir_item').each(function(index, el) { } }).done(function(data) { if (data.code == 1 && data.url) { - $(el).find('.im_img_title').before(''); + var imgHtml = ' 0) { + saveSmallImg(imgs[0]); + } + }, 100); + } }else { console.warn('目录 %s 里没有任何图片', id); }