commit d1cec341a75857e62ede166934221b7c36b19d8d Author: mei Date: Sat Jul 12 13:33:32 2025 +0800 sync diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ceaea36 --- /dev/null +++ b/.gitignore @@ -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.* + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a92cf11 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..28913f8 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Cat-API + diff --git a/config.php b/config.php new file mode 100644 index 0000000..d3f8d3f --- /dev/null +++ b/config.php @@ -0,0 +1,25 @@ + 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(); +} +?> \ No newline at end of file diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..d2a624f Binary files /dev/null and b/favicon.ico differ diff --git a/includes/announcements.php b/includes/announcements.php new file mode 100644 index 0000000..0d4f9f5 --- /dev/null +++ b/includes/announcements.php @@ -0,0 +1,25 @@ +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; +?> \ No newline at end of file diff --git a/includes/home.php b/includes/home.php new file mode 100644 index 0000000..db07c75 --- /dev/null +++ b/includes/home.php @@ -0,0 +1,242 @@ +prepare("SELECT COUNT(*) AS total FROM images"); +$stmt->execute(); +$row = $stmt->fetch(PDO::FETCH_ASSOC); +?> + + + + + + + mei API + + + + + + + +
+
+ + + + +
+ +
+
+

mei API

+
+
+

网站简介

+

欢迎使用 mei API,由 mei 开发并维护

+

用于实践我最新学到的技术,也能勉强保证服务可用性(但被打了可扛不住)

+

如果你觉得这个API有什么不完善的地方或者说你有什么更好的想♂法,可以发送邮箱至 i@mmeiblog.cn

+
+

+
+

 站点公告

+

2024-10-3

+

目前API已由无数据库的屎山代码重构为使用 Mysql 的高性能代码,旧的屎山代码已在 Github 开源,欢迎鉴赏

+
+

+
+

 友情链接

+

mei的网络日志

+
+

+
+ + + +
+
+ + + + \ No newline at end of file diff --git a/includes/pic-header.php b/includes/pic-header.php new file mode 100644 index 0000000..045cb53 --- /dev/null +++ b/includes/pic-header.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/includes/pic-push.php b/includes/pic-push.php new file mode 100644 index 0000000..cc03804 --- /dev/null +++ b/includes/pic-push.php @@ -0,0 +1,25 @@ +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; +} +?> \ No newline at end of file diff --git a/includes/pic-table-default.php b/includes/pic-table-default.php new file mode 100644 index 0000000..d0e73c7 --- /dev/null +++ b/includes/pic-table-default.php @@ -0,0 +1,25 @@ +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']); +} +?> \ No newline at end of file diff --git a/includes/pic-table-others.php b/includes/pic-table-others.php new file mode 100644 index 0000000..8f83171 --- /dev/null +++ b/includes/pic-table-others.php @@ -0,0 +1,5 @@ +prepare("SELECT {$find_field} FROM images WHERE theme = :theme"); +$stmt->bindParam(':theme', $api, PDO::PARAM_STR); +$stmt->execute(); +?> \ No newline at end of file diff --git a/includes/total-pic.php b/includes/total-pic.php new file mode 100644 index 0000000..542d177 --- /dev/null +++ b/includes/total-pic.php @@ -0,0 +1,6 @@ +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); +?> \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..e350de6 --- /dev/null +++ b/index.php @@ -0,0 +1,31 @@ + 404,'messages' => 'Not Found']); + exit; +} +?> \ No newline at end of file