Browse Source

dir snapshot get improve

master
filesite 4 months ago
parent
commit
08751d298c
  1. 19
      themes/beauty/controller/SiteController.php
  2. 9
      www/js/beauty.js

19
themes/beauty/controller/SiteController.php

@ -296,7 +296,7 @@ Class SiteController extends Controller { @@ -296,7 +296,7 @@ Class SiteController extends Controller {
$url = $cachedData['snapshot'];
$cacheSubDir = 'dir';
$size = 'vm';
Common::saveCacheToFile($cacheKey, compact('url', 'img_id', 'size'), $cacheSubDir);
Common::saveCacheToFile($cacheKey, compact('url', 'size'), $cacheSubDir);
}
}
}else {
@ -310,15 +310,19 @@ Class SiteController extends Controller { @@ -310,15 +310,19 @@ Class SiteController extends Controller {
$expireSeconds = FSC::$app['config']['screenshot_expire_seconds']; //有效期3650天
$cacheSubDir = 'image';
$cachedData = Common::getCacheFromFile($cacheKey_smimg, $expireSeconds, $cacheSubDir);
if (!empty($cachedData)) {
if (!empty($cachedData)) { //已经有缩略图
$url = $cachedData;
$img_id = ''; //无需再次生成小尺寸图片
$size = 'small';
//当前目录有缩略图的时候才缓存
$cacheSubDir = 'dir';
Common::saveCacheToFile($cacheKey, compact('url', 'size'), $cacheSubDir);
}
}else if (empty(FSC::$app['config']['enableSmallImage']) || FSC::$app['config']['enableSmallImage'] === 'false') {
//如果关闭了缩略图功能则缓存原图
$cacheSubDir = 'dir';
Common::saveCacheToFile($cacheKey, compact('url', 'size'), $cacheSubDir);
}
$cacheSubDir = 'dir';
Common::saveCacheToFile($cacheKey, compact('url', 'img_id', 'size'), $cacheSubDir);
}
}else {
$code = 0;
@ -326,11 +330,10 @@ Class SiteController extends Controller { @@ -326,11 +330,10 @@ Class SiteController extends Controller {
}
}else {
$url = $cachedData['url'];
$img_id = $cachedData['img_id'];
}
}
return $this->renderJson(compact('code', 'msg', 'url', 'img_id'));
return $this->renderJson(compact('code', 'msg', 'url'));
}
//保存目录封面图到缓存

9
www/js/beauty.js

@ -311,15 +311,6 @@ $('.dir_item').each(function(index, el) { @@ -311,15 +311,6 @@ $('.dir_item').each(function(index, el) {
}
imgHtml += ' class="bor_radius im_img">';
$(el).find('.im_img_title').before(imgHtml);
if (data.img_id) {
setTimeout(function() {
var imgs = $(el).find('.im_img');
if (imgs.length > 0) {
saveSmallImg(imgs[0], id);
}
}, 100);
}
}else {
//console.warn('目录 %s 里没有任何图片', id);
var imgHtml = '<img src="/img/default.png">';

Loading…
Cancel
Save