sync
This commit is contained in:
commit
d1cec341a7
132
.gitignore
vendored
Normal file
132
.gitignore
vendored
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
# ---> Node
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
*.lcov
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# Snowpack dependency directory (https://snowpack.dev/)
|
||||||
|
web_modules/
|
||||||
|
|
||||||
|
# TypeScript cache
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional stylelint cache
|
||||||
|
.stylelintcache
|
||||||
|
|
||||||
|
# Microbundle cache
|
||||||
|
.rpt2_cache/
|
||||||
|
.rts2_cache_cjs/
|
||||||
|
.rts2_cache_es/
|
||||||
|
.rts2_cache_umd/
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variable files
|
||||||
|
.env
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
.env.local
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
.cache
|
||||||
|
.parcel-cache
|
||||||
|
|
||||||
|
# Next.js build output
|
||||||
|
.next
|
||||||
|
out
|
||||||
|
|
||||||
|
# Nuxt.js build / generate output
|
||||||
|
.nuxt
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Gatsby files
|
||||||
|
.cache/
|
||||||
|
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||||
|
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||||
|
# public
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# vuepress v2.x temp and cache directory
|
||||||
|
.temp
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# Docusaurus cache and generated files
|
||||||
|
.docusaurus
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
.serverless/
|
||||||
|
|
||||||
|
# FuseBox cache
|
||||||
|
.fusebox/
|
||||||
|
|
||||||
|
# DynamoDB Local files
|
||||||
|
.dynamodb/
|
||||||
|
|
||||||
|
# TernJS port file
|
||||||
|
.tern-port
|
||||||
|
|
||||||
|
# Stores VSCode versions used for testing VSCode extensions
|
||||||
|
.vscode-test
|
||||||
|
|
||||||
|
# yarn v2
|
||||||
|
.yarn/cache
|
||||||
|
.yarn/unplugged
|
||||||
|
.yarn/build-state.yml
|
||||||
|
.yarn/install-state.gz
|
||||||
|
.pnp.*
|
||||||
|
|
9
LICENSE
Normal file
9
LICENSE
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 mei
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
config.php
Normal file
25
config.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
$baseURL = 'https://api.mmeiblog.cn/'; // 后面要加 "/"
|
||||||
|
$base_img_path = 'files/img/'; // 图片路径
|
||||||
|
$icon_font = '//at.alicdn.com/t/c/font_4536557_e64emmx4sxm.css'; // 阿里图标库
|
||||||
|
|
||||||
|
// 时间段
|
||||||
|
$Time_period_mapping = [
|
||||||
|
['start' => 0, 'end' => 7, 'Time_period' => 'dark'],
|
||||||
|
['start' => 7, 'end' => 19, 'Time_period' => 'light'],
|
||||||
|
['start' => 19, 'end' => 24, 'Time_period' => 'dark'],
|
||||||
|
];
|
||||||
|
|
||||||
|
// 数据库
|
||||||
|
$host = 'host';
|
||||||
|
$db = 'database';
|
||||||
|
$user = 'username';
|
||||||
|
$pass = 'password';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
|
||||||
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "Connection failed: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
?>
|
BIN
favicon.ico
Normal file
BIN
favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 272 KiB |
25
includes/announcements.php
Normal file
25
includes/announcements.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
$sql = "SELECT `date`, `content` FROM announcement ORDER BY `date` DESC"; // 按日期降序排列
|
||||||
|
$stmt = $pdo->prepare($sql);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
// 获取查询结果
|
||||||
|
$announcements = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
// 处理日期格式
|
||||||
|
foreach ($announcements as &$announcement) {
|
||||||
|
$announcement['date'] = date('Y-m-d', strtotime($announcement['date']));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 准备返回的数据
|
||||||
|
$response = [
|
||||||
|
"code" => 200,
|
||||||
|
"announcements" => $announcements,
|
||||||
|
"message" => "Success"
|
||||||
|
];
|
||||||
|
|
||||||
|
// 将数组转换为 JSON 格式
|
||||||
|
$json_response = json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||||
|
|
||||||
|
echo $json_response;
|
||||||
|
?>
|
242
includes/home.php
Normal file
242
includes/home.php
Normal file
@ -0,0 +1,242 @@
|
|||||||
|
<?php
|
||||||
|
$stmt = $pdo->prepare("SELECT COUNT(*) AS total FROM images");
|
||||||
|
$stmt->execute();
|
||||||
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-Hans">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>mei API</title>
|
||||||
|
<link rel="stylesheet" href="/assets/css/style.css">
|
||||||
|
<link rel="stylesheet" href="//at.alicdn.com/t/c/font_4536557_e64emmx4sxm.css">
|
||||||
|
<script src="/assets/js/jquery.min.js"></script>
|
||||||
|
<?php echo $umami; ?>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<div class="vertical-line"></div>
|
||||||
|
<!-- 侧边栏 -->
|
||||||
|
<div class="sidebar" id="sidebar">
|
||||||
|
<div class="menu-item" onclick="showContent('home')">
|
||||||
|
<span class="iconfont icon-shouye" style="font-size:17px;"></span>
|
||||||
|
 首页
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> <small>图片API</small></p>
|
||||||
|
|
||||||
|
<div class="menu-item" onclick="showContent('pic')">
|
||||||
|
<span class="iconfont icon-tupian" style="font-size:17px;color:#158b8f;"></span>
|
||||||
|
 随机图片
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 内容 -->
|
||||||
|
<div class="content">
|
||||||
|
<!-- 首页 -->
|
||||||
|
<div id="home">
|
||||||
|
<center>
|
||||||
|
<h2>mei API</h2>
|
||||||
|
</center>
|
||||||
|
<div class="text">
|
||||||
|
<h4>网站简介</h4>
|
||||||
|
<p>欢迎使用 <code>mei API</code>,由 mei 开发并维护</p>
|
||||||
|
<p>用于实践我最新学到的技术,也能勉强保证服务可用性(但被打了可扛不住)</p>
|
||||||
|
<p>如果你觉得这个API有什么不完善的地方或者说你有什么更好的想♂法,可以发送邮箱至 <a href=mailto:i@mmeiblog.cn>i@mmeiblog.cn</a>。</p>
|
||||||
|
</div>
|
||||||
|
</br></br>
|
||||||
|
<div class="text">
|
||||||
|
<h4><span class="iconfont icon-gonggao" style="font-size:20px;color:#515B77;"></span> 站点公告</h4>
|
||||||
|
<p><small>2024-10-3</small></p>
|
||||||
|
<p>目前API已由无数据库的屎山代码重构为使用 Mysql 的高性能代码,旧的屎山代码已在 Github 开源,欢迎鉴赏</p></hr>
|
||||||
|
</div>
|
||||||
|
</br></br>
|
||||||
|
<div class="text">
|
||||||
|
<h4><span class="iconfont icon-youlian" style="font-size:20px;"></span> 友情链接</h4>
|
||||||
|
<p><a href="https://mei.lv">mei的网络日志</a></p>
|
||||||
|
</div>
|
||||||
|
<p style="text-align: right;"><small><span class="iconfont icon-git-fenzhi-tianchong"
|
||||||
|
style="font-size:15px"></span><?php echo $git_commits; ?></small></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 随机图片 -->
|
||||||
|
<div id="pic" style="display:none;">
|
||||||
|
<center>
|
||||||
|
<h1>随机图片 API</h1>
|
||||||
|
<p>此 API 提供随机二次元图片,不定期更新!</p>
|
||||||
|
<p>图片总数:<?php echo $row['total']; ?></p>
|
||||||
|
</center>
|
||||||
|
<div class="text">
|
||||||
|
<h2>
|
||||||
|
<span class="iconfont icon-lianjie" style="font-size:28px;color:#1677FF;"></span>
|
||||||
|
API 地址
|
||||||
|
</h2>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>#</th>
|
||||||
|
<th>适用设备</th>
|
||||||
|
<th>请求方式</th>
|
||||||
|
<th>请求地址</th>
|
||||||
|
<th>说明</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>1</td>
|
||||||
|
<td>手机</td>
|
||||||
|
<td>GET</td>
|
||||||
|
<td><a href="phone">/phone</a></td>
|
||||||
|
<td>竖屏随机图片API</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>2</td>
|
||||||
|
<td>电脑</td>
|
||||||
|
<td>GET</td>
|
||||||
|
<td><a href="pc">/pc</a></td>
|
||||||
|
<td>横屏随机图片API</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>3</td>
|
||||||
|
<td>All</td>
|
||||||
|
<td>GET</td>
|
||||||
|
<td><a href="favicon">/favicon</a></td>
|
||||||
|
<td>获取本站favicon</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>4</td>
|
||||||
|
<td>All</td>
|
||||||
|
<td>GET</td>
|
||||||
|
<td><a href="bj">/bj</a></td>
|
||||||
|
<td>获取静态页面装饰图</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>5</td>
|
||||||
|
<td>All</td>
|
||||||
|
<td>GET</td>
|
||||||
|
<td><a href="fox">/fox</a></td>
|
||||||
|
<td>获取狐狸图</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</br></br>
|
||||||
|
|
||||||
|
<div class="text">
|
||||||
|
<h2>
|
||||||
|
<span class="iconfont icon-_canshu_xiugaicanshudingyi" style="font-size:25px;"></span>
|
||||||
|
参数列表
|
||||||
|
</h2>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>#</th>
|
||||||
|
<th>参数</th>
|
||||||
|
<th>值</th>
|
||||||
|
<th>说明</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>1</td>
|
||||||
|
<td>time</td>
|
||||||
|
<td>Boolean</td>
|
||||||
|
<td>是否区分时段,默认为<code>false</code></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>2</td>
|
||||||
|
<td>mode</td>
|
||||||
|
<td>String</td>
|
||||||
|
<td>填<code>json</code>则返回一串数组;填<code>redirect</code>则会重定向至图片URL;不填则返回一张图片</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>3</td>
|
||||||
|
<td>source</td>
|
||||||
|
<td>Boolean</td>
|
||||||
|
<td>是否使用原图(加载较慢),默认为<code>true</code></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</br></br>
|
||||||
|
|
||||||
|
<div class="text">
|
||||||
|
<h2>
|
||||||
|
<span class="iconfont icon-icon--fanhui" style="font-size:25px;color:#1677FF;"></span>
|
||||||
|
返回数据
|
||||||
|
</h2>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>#</td>
|
||||||
|
<th>数据</td>
|
||||||
|
<th>说明</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>1</td>
|
||||||
|
<td>code</td>
|
||||||
|
<td>状态码</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>2</td>
|
||||||
|
<td>image_url</td>
|
||||||
|
<td>图片地址</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>3</td>
|
||||||
|
<td>theme</td>
|
||||||
|
<td>明暗主题</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>4</td>
|
||||||
|
<td>endpoint_type</td>
|
||||||
|
<td>适用设备</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>5</td>
|
||||||
|
<td>now</td>
|
||||||
|
<td>现在的时间</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>6</td>
|
||||||
|
<td>mode</td>
|
||||||
|
<td>输出模式</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
function showContent(id) {
|
||||||
|
var contentSections = document.querySelectorAll('.content > div');
|
||||||
|
for (var i = 0; i < contentSections.length; i++) {
|
||||||
|
contentSections[i].style.display = 'none';
|
||||||
|
}
|
||||||
|
document.getElementById(id).style.display = 'block';
|
||||||
|
}
|
||||||
|
// Linuxcat
|
||||||
|
console.log("Linuxcat_mei");
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
13
includes/pic-header.php
Normal file
13
includes/pic-header.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
// 获取 GET 参数
|
||||||
|
$source = $_GET['source'] ?? true;
|
||||||
|
$time = $_GET['time'];
|
||||||
|
$mode = $_GET['mode'];
|
||||||
|
$et = $_GET['et'];
|
||||||
|
|
||||||
|
// 将 $source 转换为布尔值
|
||||||
|
$source_bool = filter_var($source, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
|
||||||
|
|
||||||
|
// 根据 $source 的布尔值设置 $find_field
|
||||||
|
$find_field = $source_bool === false ? 'webp_path' : 'filename';
|
||||||
|
?>
|
25
includes/pic-push.php
Normal file
25
includes/pic-push.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
// 路径计算
|
||||||
|
$filenames = $stmt->fetchAll(PDO::FETCH_COLUMN, 0); // 从数据库取出的文件名
|
||||||
|
$random_filename = $filenames[array_rand($filenames)]; // 随机一个文件名
|
||||||
|
$push_path = $base_img_path . $random_filename; // 相对路径
|
||||||
|
$imageUrl = $baseURL . $push_path; // URL
|
||||||
|
|
||||||
|
// 返还数据
|
||||||
|
if (empty($mode)) {
|
||||||
|
header('Content-Type: image/jpeg');
|
||||||
|
header('Content-Length: ' . filesize($push_path));
|
||||||
|
readfile($push_path);
|
||||||
|
exit;
|
||||||
|
} elseif ($mode == 'json') {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode(['code' => 200, 'image_url' => $imageUrl, 'endpoint_type' => $et, 'time' => $time, 'is_source' => $source, 'mode' => 'json']);
|
||||||
|
exit;
|
||||||
|
} elseif ($mode == 'redirect') {
|
||||||
|
header('Location: ' . $imageUrl);
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
header('Location: ' . $imageUrl);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
?>
|
25
includes/pic-table-default.php
Normal file
25
includes/pic-table-default.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
// 查表
|
||||||
|
if (empty($time) || $time == False) {
|
||||||
|
$stmt = $pdo->prepare("SELECT {$find_field} FROM images WHERE et = :et");
|
||||||
|
$stmt->bindParam(':et', $et, PDO::PARAM_STR);
|
||||||
|
$stmt->execute();
|
||||||
|
} elseif ($time == True) {
|
||||||
|
$now_time = date('G');
|
||||||
|
$selected_period = null;
|
||||||
|
foreach ($Time_period_mapping as $timeFrame) {
|
||||||
|
if ($now_time >= $timeFrame['start'] && $now_time < $timeFrame['end']) {
|
||||||
|
$selected_period = $timeFrame['Time_period'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$stmt = $pdo->prepare("SELECT {$find_field} FROM images WHERE et = :et AND theme = :theme");
|
||||||
|
$stmt->bindParam(':et', $et, PDO::PARAM_STR);
|
||||||
|
$stmt->bindParam(':theme', $selected_period, PDO::PARAM_STR);
|
||||||
|
$stmt->execute();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
json_encode(['code' => 404, 'warn' => 'Please check the parameters', 'endpoint_type' => $et, 'time' => $time, 'mode' => 'json']);
|
||||||
|
}
|
||||||
|
?>
|
5
includes/pic-table-others.php
Normal file
5
includes/pic-table-others.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
$stmt = $pdo->prepare("SELECT {$find_field} FROM images WHERE theme = :theme");
|
||||||
|
$stmt->bindParam(':theme', $api, PDO::PARAM_STR);
|
||||||
|
$stmt->execute();
|
||||||
|
?>
|
6
includes/total-pic.php
Normal file
6
includes/total-pic.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
$stmt = $pdo->prepare("SELECT COUNT(*) AS total FROM images");
|
||||||
|
$stmt->execute();
|
||||||
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
echo json_encode(['code' => '200', 'count' => $row['total'], 'message' => 'Success'], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||||
|
?>
|
31
index.php
Normal file
31
index.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
include('config.php');
|
||||||
|
|
||||||
|
// 安全地获取API名称
|
||||||
|
$api = isset($_GET['api']) ? $_GET['api'] : '';
|
||||||
|
|
||||||
|
// 白名单验证
|
||||||
|
$allowedApis = ['pic', 'favicon', 'bj', 'fox', 'total-pic', 'announcements'];
|
||||||
|
|
||||||
|
if (empty($api)) {
|
||||||
|
include('includes/home.php');
|
||||||
|
} elseif (in_array($api, $allowedApis)) {
|
||||||
|
if ($api === 'pic') {
|
||||||
|
include('includes/pic-header.php');
|
||||||
|
include('includes/pic-table-default.php');
|
||||||
|
include('includes/pic-push.php');
|
||||||
|
} elseif (in_array($api, ['favicon', 'bj', 'fox'])) {
|
||||||
|
include('includes/pic-header.php');
|
||||||
|
include('includes/pic-table-others.php');
|
||||||
|
include('includes/pic-push.php');
|
||||||
|
} else { // 'total-pic' or 'announcements'
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
include ('includes/' . $api . '.php');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
http_response_code(404);
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode(['code' => 404,'messages' => 'Not Found']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
?>
|
Loading…
Reference in New Issue
Block a user