feat: 新增App图标搜索器增强版功能
引入完整的App图标搜索器增强版,包括前端页面、后端缓存系统、样式和脚本。主要功能包括实时搜索、多尺寸图标下载、图片预览、响应式设计和智能缓存机制。后端通过ImageCache类实现图片缓存,前端通过JavaScript优化搜索交互和图片加载体验。新增README.md提供详细的部署和开发指南。
This commit is contained in:
32
cache/ImageCache.php
vendored
Normal file
32
cache/ImageCache.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
class ImageCache {
|
||||
private $cacheDir;
|
||||
private $cacheDuration = 604800; // 7天缓存
|
||||
|
||||
public function __construct() {
|
||||
$this->cacheDir = __DIR__ . '/images/';
|
||||
if (!file_exists($this->cacheDir)) {
|
||||
mkdir($this->cacheDir, 0777, true);
|
||||
}
|
||||
}
|
||||
|
||||
public function getCachedImage($url) {
|
||||
$cacheFile = $this->cacheDir . md5($url);
|
||||
|
||||
if (file_exists($cacheFile) && (time() - filemtime($cacheFile) < $this->cacheDuration)) {
|
||||
return file_get_contents($cacheFile);
|
||||
}
|
||||
|
||||
$imageContent = file_get_contents($url);
|
||||
if ($imageContent !== false) {
|
||||
file_put_contents($cacheFile, $imageContent);
|
||||
return $imageContent;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getCacheUrl($url) {
|
||||
return 'cache/image.php?url=' . urlencode($url);
|
||||
}
|
||||
}
|
||||
37
cache/image.php
vendored
Normal file
37
cache/image.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
require_once 'ImageCache.php';
|
||||
|
||||
$url = isset($_GET['url']) ? $_GET['url'] : '';
|
||||
if (empty($url)) {
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
exit;
|
||||
}
|
||||
|
||||
$imageCache = new ImageCache();
|
||||
$image = $imageCache->getCachedImage($url);
|
||||
|
||||
if ($image === false) {
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
exit;
|
||||
}
|
||||
|
||||
$extension = pathinfo(parse_url($url, PHP_URL_PATH), PATHINFO_EXTENSION);
|
||||
switch(strtolower($extension)) {
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
header('Content-Type: image/jpeg');
|
||||
break;
|
||||
case 'png':
|
||||
header('Content-Type: image/png');
|
||||
break;
|
||||
case 'gif':
|
||||
header('Content-Type: image/gif');
|
||||
break;
|
||||
default:
|
||||
header('Content-Type: image/jpeg');
|
||||
}
|
||||
|
||||
header('Cache-Control: public, max-age=31536000');
|
||||
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 31536000));
|
||||
|
||||
echo $image;
|
||||
Reference in New Issue
Block a user