diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..78dbedc --- /dev/null +++ b/.gitignore @@ -0,0 +1,45 @@ +# Dependencies +node_modules/ +package-lock.json +# (Keep package-lock.json if you want to lock versions, but some prefer to ignore. Standard is to KEEP it, but I'll list node_modules which is the big one) + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Database +*.db +*.sqlite +webs/genshin.db + +# OS generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# IDEs and Editors +.idea/ +.vscode/ +*.swp +*.swo + +# Environment variables +.env +.env.test +.env.production + +# Optional: Verce output +.vercel diff --git a/api/index.php b/api/index.php deleted file mode 100644 index e37567b..0000000 --- a/api/index.php +++ /dev/null @@ -1,12 +0,0 @@ - + 原神主题网站 | Genshin Theme diff --git a/package.json b/package.json new file mode 100644 index 0000000..b86e2ec --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "genshin-impart", + "version": "1.0.0", + "description": "本网站所参考的源码:[Herta Kuru~](https://github.com/duiqt/herta_kuru) |", + "main": "indexscript.js", + "scripts": { + "start": "node server.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "body-parser": "^2.2.1", + "cors": "^2.8.5", + "express": "^5.1.0", + "sqlite3": "^5.1.7" + } +} diff --git a/server.js b/server.js new file mode 100644 index 0000000..22036e3 --- /dev/null +++ b/server.js @@ -0,0 +1,93 @@ +const express = require('express'); +const sqlite3 = require('sqlite3').verbose(); +const bodyParser = require('body-parser'); +const cors = require('cors'); +const path = require('path'); +const fs = require('fs'); + +const app = express(); +const PORT = process.env.PORT || 3000; + +// Middleware +app.use(cors()); +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: true })); + +// Database setup +const dbFile = path.join(__dirname, 'webs', 'genshin.db'); +const db = new sqlite3.Database(dbFile, (err) => { + if (err) { + console.error('Error opening database:', err.message); + } else { + console.log('Connected to the SQLite database.'); + initializeDatabase(); + } +}); + +function initializeDatabase() { + db.serialize(() => { + db.run(`CREATE TABLE IF NOT EXISTS ys ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT NOT NULL UNIQUE, + globalcount INTEGER DEFAULT 0 + )`); + + const characters = ['klee', 'nahida', 'kirara', 'dori', 'babara']; + const stmt = db.prepare("INSERT OR IGNORE INTO ys (name, globalcount) VALUES (?, 0)"); + characters.forEach(char => { + stmt.run(char); + }); + stmt.finalize(); + console.log('Database initialized.'); + }); +} + +// Serve static files +// Serve root files (index.html, img, etc.) +app.use(express.static(path.join(__dirname))); + +// API Routes + +// Get count +app.get('/api/count/:name', (req, res) => { + const name = req.params.name; + db.get("SELECT globalcount FROM ys WHERE name = ?", [name], (err, row) => { + if (err) { + res.status(500).json({ error: err.message }); + return; + } + if (row) { + // Format matches the previous PHP array structure: [{globalcount: 123}] + res.json([{ globalcount: row.globalcount }]); + } else { + res.status(404).json({ error: "Character not found" }); + } + }); +}); + +// Update count +app.post('/api/count/:name', (req, res) => { + const name = req.params.name; + const localCount = parseInt(req.body.localcount) || 0; + + // First get current count to add to it (though atomic update is better) + // Using atomic update directly: + db.run("UPDATE ys SET globalcount = globalcount + ? WHERE name = ?", [localCount, name], function(err) { + if (err) { + res.status(500).send("Update failed: " + err.message); + return; + } + if (this.changes > 0) { + res.send("更新成功"); + } else { + res.send("没有找到全局计数值"); // Or create if not exists + } + }); +}); + +// Fallback for specific PHP routes to redirect/handle gracefully if needed, +// but we will update frontend to use /api/count/:name. + +app.listen(PORT, () => { + console.log(`Server running on http://localhost:${PORT}`); +}); diff --git a/vercel.json b/vercel.json index ef55f26..1def834 100644 --- a/vercel.json +++ b/vercel.json @@ -1,10 +1,15 @@ { - "functions": { - "api/index.php": { - "runtime": "vercel-php@0.7.0" + "version": 2, + "builds": [ + { + "src": "server.js", + "use": "@vercel/node" } - }, + ], "routes": [ - { "src": "/(.*)", "dest": "/api/index.php" } + { + "src": "/(.*)", + "dest": "/server.js" + } ] } diff --git a/webs/BabaraWeb/babara.html b/webs/BabaraWeb/babara.html index 8c5abfb..44904b0 100644 --- a/webs/BabaraWeb/babara.html +++ b/webs/BabaraWeb/babara.html @@ -3,7 +3,8 @@ - Babara~ + Kirakira~ + diff --git a/webs/BabaraWeb/babara.php b/webs/BabaraWeb/babara.php deleted file mode 100644 index c878b53..0000000 --- a/webs/BabaraWeb/babara.php +++ /dev/null @@ -1,62 +0,0 @@ -query($sql); - -if ($_SERVER["REQUEST_METHOD"] === "POST") { - // 处理 POST 请求 - //接收前端数据 - $localcount = $_POST["localcount"]; - //检查查询结果 - if ($result->num_rows > 0) { - $row = $result->fetch_assoc(); - $globalCount = $row['globalcount']; - - // 将本地计数值加给全局计数 - $globalCount += $localcount; - - // 更新数据库中的全局计数值 - $updateSql = "UPDATE ys SET globalcount = $globalCount WHERE name = 'babara';"; - - if ($conn->query($updateSql) === TRUE) { - // 更新成功 - echo "更新成功"; - } else { - // 更新失败 - echo "更新失败: " . $conn->error; - } - } else { - // 没有找到全局计数值 - echo "没有找到全局计数值"; - } - - // 返回响应 - //echo "这是 POST 请求的响应"; -} elseif ($_SERVER["REQUEST_METHOD"] === "GET") { - // 处理 GET 请求 - if ($result->num_rows > 0) { - // 有数据返回 - $rows = array(); - while ($row = $result->fetch_assoc()) { - $rows[] = $row; - } - // 将查询结果转换为 JSON 格式发送回前端 - echo json_encode($rows); - } else { - // 无数据返回 - echo "没有数据"; - } - // 返回响应 - //echo "这是 GET 请求的响应"; -} else { - // 不支持其他请求方法 - http_response_code(405); // 返回“Method Not Allowed”状态码 - echo "不支持的请求方法"; -} - -?> \ No newline at end of file diff --git a/webs/BabaraWeb/babarascript.js b/webs/BabaraWeb/babarascript.js index c05a2e2..cd94653 100644 --- a/webs/BabaraWeb/babarascript.js +++ b/webs/BabaraWeb/babarascript.js @@ -537,7 +537,7 @@ $(document).ready(function () { //上传数据 function updateGlobalCount() { $.ajax({ - url: './babara.php', + url: '/api/count/babara', method: 'POST', async: false, data: { localcount: thisTimeCounts }, @@ -560,7 +560,7 @@ function updateGlobalCount() { //首次访问网站的时候,立即获取 globalCounts并刷新 (页面加载完成后立即执行) document.addEventListener("DOMContentLoaded", function () { $.ajax({ - url: './babara.php', + url: '/api/count/babara', method: 'GET', dataType: 'json', headers: { @@ -586,7 +586,7 @@ function updateGlobalCount() { // 定时轮询后端获取 globalCounts setInterval(function () { $.ajax({ - url: './babara.php', + url: '/api/count/babara', method: 'GET', dataType: 'json', headers: { diff --git a/webs/DoriWeb/dori.html b/webs/DoriWeb/dori.html index 2e6c99c..5dcbb70 100644 --- a/webs/DoriWeb/dori.html +++ b/webs/DoriWeb/dori.html @@ -3,7 +3,8 @@ - ❤Duang~ + Duang~ + diff --git a/webs/DoriWeb/dori.php b/webs/DoriWeb/dori.php deleted file mode 100644 index f781f5d..0000000 --- a/webs/DoriWeb/dori.php +++ /dev/null @@ -1,62 +0,0 @@ -query($sql); - -if ($_SERVER["REQUEST_METHOD"] === "POST") { - // 处理 POST 请求 - //接收前端数据 - $localcount = $_POST["localcount"]; - //检查查询结果 - if ($result->num_rows > 0) { - $row = $result->fetch_assoc(); - $globalCount = $row['globalcount']; - - // 将本地计数值加给全局计数 - $globalCount += $localcount; - - // 更新数据库中的全局计数值 - $updateSql = "UPDATE ys SET globalcount = $globalCount WHERE name = 'dori';"; - - if ($conn->query($updateSql) === TRUE) { - // 更新成功 - echo "更新成功"; - } else { - // 更新失败 - echo "更新失败: " . $conn->error; - } - } else { - // 没有找到全局计数值 - echo "没有找到全局计数值"; - } - - // 返回响应 - //echo "这是 POST 请求的响应"; -} elseif ($_SERVER["REQUEST_METHOD"] === "GET") { - // 处理 GET 请求 - if ($result->num_rows > 0) { - // 有数据返回 - $rows = array(); - while ($row = $result->fetch_assoc()) { - $rows[] = $row; - } - // 将查询结果转换为 JSON 格式发送回前端 - echo json_encode($rows); - } else { - // 无数据返回 - echo "没有数据"; - } - // 返回响应 - //echo "这是 GET 请求的响应"; -} else { - // 不支持其他请求方法 - http_response_code(405); // 返回“Method Not Allowed”状态码 - echo "不支持的请求方法"; -} - -?> \ No newline at end of file diff --git a/webs/DoriWeb/doriscript.js b/webs/DoriWeb/doriscript.js index 1ffc848..766fca2 100644 --- a/webs/DoriWeb/doriscript.js +++ b/webs/DoriWeb/doriscript.js @@ -549,7 +549,7 @@ $(document).ready(function () { //上传数据 function updateGlobalCount() { $.ajax({ - url: './dori.php', + url: '/api/count/dori', method: 'POST', async: false, data: { localcount: thisTimeCounts }, @@ -572,7 +572,7 @@ function updateGlobalCount() { //首次访问网站的时候,立即获取 globalCounts并刷新 (页面加载完成后立即执行) document.addEventListener("DOMContentLoaded", function () { $.ajax({ - url: './dori.php', + url: '/api/count/dori', method: 'GET', dataType: 'json', headers: { @@ -598,7 +598,7 @@ function updateGlobalCount() { // 定时轮询后端获取 globalCounts setInterval(function () { $.ajax({ - url: './dori.php', + url: '/api/count/dori', method: 'GET', dataType: 'json', headers: { diff --git a/webs/KiraraWeb/kirara.html b/webs/KiraraWeb/kirara.html index 089d65a..9eea3db 100644 --- a/webs/KiraraWeb/kirara.html +++ b/webs/KiraraWeb/kirara.html @@ -3,7 +3,8 @@ - Miaouuuu~ + Meow~ + diff --git a/webs/KiraraWeb/kirara.php b/webs/KiraraWeb/kirara.php deleted file mode 100644 index f2800f4..0000000 --- a/webs/KiraraWeb/kirara.php +++ /dev/null @@ -1,62 +0,0 @@ -query($sql); - -if ($_SERVER["REQUEST_METHOD"] === "POST") { - // 处理 POST 请求 - //接收前端数据 - $localcount = $_POST["localcount"]; - //检查查询结果 - if ($result->num_rows > 0) { - $row = $result->fetch_assoc(); - $globalCount = $row['globalcount']; - - // 将本地计数值加给全局计数 - $globalCount += $localcount; - - // 更新数据库中的全局计数值 - $updateSql = "UPDATE ys SET globalcount = $globalCount WHERE name = 'kirara';"; - - if ($conn->query($updateSql) === TRUE) { - // 更新成功 - echo "更新成功"; - } else { - // 更新失败 - echo "更新失败: " . $conn->error; - } - } else { - // 没有找到全局计数值 - echo "没有找到全局计数值"; - } - - // 返回响应 - //echo "这是 POST 请求的响应"; -} elseif ($_SERVER["REQUEST_METHOD"] === "GET") { - // 处理 GET 请求 - if ($result->num_rows > 0) { - // 有数据返回 - $rows = array(); - while ($row = $result->fetch_assoc()) { - $rows[] = $row; - } - // 将查询结果转换为 JSON 格式发送回前端 - echo json_encode($rows); - } else { - // 无数据返回 - echo "没有数据"; - } - // 返回响应 - //echo "这是 GET 请求的响应"; -} else { - // 不支持其他请求方法 - http_response_code(405); // 返回“Method Not Allowed”状态码 - echo "不支持的请求方法"; -} - -?> \ No newline at end of file diff --git a/webs/KiraraWeb/kirarascript.js b/webs/KiraraWeb/kirarascript.js index 73e75d2..23450bc 100644 --- a/webs/KiraraWeb/kirarascript.js +++ b/webs/KiraraWeb/kirarascript.js @@ -543,7 +543,7 @@ $(document).ready(function () { //上传数据 function updateGlobalCount() { $.ajax({ - url: './kirara.php', + url: '/api/count/kirara', method: 'POST', async: false, data: { localcount: thisTimeCounts }, @@ -566,7 +566,7 @@ function updateGlobalCount() { //首次访问网站的时候,立即获取 globalCounts并刷新 (页面加载完成后立即执行) document.addEventListener("DOMContentLoaded", function () { $.ajax({ - url: './kirara.php', + url: '/api/count/kirara', method: 'GET', dataType: 'json', headers: { @@ -592,7 +592,7 @@ function updateGlobalCount() { // 定时轮询后端获取 globalCounts setInterval(function () { $.ajax({ - url: './kirara.php', + url: '/api/count/kirara', method: 'GET', dataType: 'json', headers: { diff --git a/webs/KleeWeb/klee.html b/webs/KleeWeb/klee.html index a36959a..7185749 100644 --- a/webs/KleeWeb/klee.html +++ b/webs/KleeWeb/klee.html @@ -4,6 +4,7 @@ DaDaDa~ + diff --git a/webs/KleeWeb/klee.php b/webs/KleeWeb/klee.php deleted file mode 100644 index 5fbb645..0000000 --- a/webs/KleeWeb/klee.php +++ /dev/null @@ -1,62 +0,0 @@ -query($sql); - -if ($_SERVER["REQUEST_METHOD"] === "POST") { - // 处理 POST 请求 - //接收前端数据 - $localcount = $_POST["localcount"]; - //检查查询结果 - if ($result->num_rows > 0) { - $row = $result->fetch_assoc(); - $globalCount = $row['globalcount']; - - // 将本地计数值加给全局计数 - $globalCount += $localcount; - - // 更新数据库中的全局计数值 - $updateSql = "UPDATE ys SET globalcount = $globalCount WHERE name = 'klee';"; - - if ($conn->query($updateSql) === TRUE) { - // 更新成功 - echo "更新成功"; - } else { - // 更新失败 - echo "更新失败: " . $conn->error; - } - } else { - // 没有找到全局计数值 - echo "没有找到全局计数值"; - } - - // 返回响应 - //echo "这是 POST 请求的响应"; -} elseif ($_SERVER["REQUEST_METHOD"] === "GET") { - // 处理 GET 请求 - if ($result->num_rows > 0) { - // 有数据返回 - $rows = array(); - while ($row = $result->fetch_assoc()) { - $rows[] = $row; - } - // 将查询结果转换为 JSON 格式发送回前端 - echo json_encode($rows); - } else { - // 无数据返回 - echo "没有数据"; - } - // 返回响应 - //echo "这是 GET 请求的响应"; -} else { - // 不支持其他请求方法 - http_response_code(405); // 返回“Method Not Allowed”状态码 - echo "不支持的请求方法"; -} - -?> \ No newline at end of file diff --git a/webs/KleeWeb/kleescript.js b/webs/KleeWeb/kleescript.js index 01c552c..77a9ab8 100644 --- a/webs/KleeWeb/kleescript.js +++ b/webs/KleeWeb/kleescript.js @@ -584,7 +584,7 @@ $(document).ready(function () { //上传数据 function updateGlobalCount() { $.ajax({ - url: './klee.php', + url: '/api/count/klee', method: 'POST', async: false, data: { localcount: thisTimeCounts }, @@ -607,7 +607,7 @@ function updateGlobalCount() { //首次访问网站的时候,立即获取 globalCounts并刷新 (页面加载完成后立即执行) document.addEventListener("DOMContentLoaded", function () { $.ajax({ - url: './klee.php', + url: '/api/count/klee', method: 'GET', dataType: 'json', headers: { @@ -633,7 +633,7 @@ document.addEventListener("DOMContentLoaded", function () { // 定时轮询后端获取 globalCounts setInterval(function () { $.ajax({ - url: './klee.php', + url: '/api/count/klee', method: 'GET', dataType: 'json', headers: { diff --git a/webs/NahidaWeb/nahida.html b/webs/NahidaWeb/nahida.html index 848ab1e..bcae058 100644 --- a/webs/NahidaWeb/nahida.html +++ b/webs/NahidaWeb/nahida.html @@ -4,6 +4,7 @@ Nahida~ + diff --git a/webs/NahidaWeb/nahida.php b/webs/NahidaWeb/nahida.php deleted file mode 100644 index 1eda5f8..0000000 --- a/webs/NahidaWeb/nahida.php +++ /dev/null @@ -1,62 +0,0 @@ -query($sql); - -if ($_SERVER["REQUEST_METHOD"] === "POST") { - // 处理 POST 请求 - //接收前端数据 - $localcount = $_POST["localcount"]; - //检查查询结果 - if ($result->num_rows > 0) { - $row = $result->fetch_assoc(); - $globalCount = $row['globalcount']; - - // 将本地计数值加给全局计数 - $globalCount += $localcount; - - // 更新数据库中的全局计数值 - $updateSql = "UPDATE ys SET globalcount = $globalCount WHERE name = 'nahida';"; - - if ($conn->query($updateSql) === TRUE) { - // 更新成功 - echo "更新成功"; - } else { - // 更新失败 - echo "更新失败: " . $conn->error; - } - } else { - // 没有找到全局计数值 - echo "没有找到全局计数值"; - } - - // 返回响应 - //echo "这是 POST 请求的响应"; -} elseif ($_SERVER["REQUEST_METHOD"] === "GET") { - // 处理 GET 请求 - if ($result->num_rows > 0) { - // 有数据返回 - $rows = array(); - while ($row = $result->fetch_assoc()) { - $rows[] = $row; - } - // 将查询结果转换为 JSON 格式发送回前端 - echo json_encode($rows); - } else { - // 无数据返回 - echo "没有数据"; - } - // 返回响应 - //echo "这是 GET 请求的响应"; -} else { - // 不支持其他请求方法 - http_response_code(405); // 返回“Method Not Allowed”状态码 - echo "不支持的请求方法"; -} - -?> \ No newline at end of file diff --git a/webs/NahidaWeb/nahidascript.js b/webs/NahidaWeb/nahidascript.js index 8d61ca7..b002cec 100644 --- a/webs/NahidaWeb/nahidascript.js +++ b/webs/NahidaWeb/nahidascript.js @@ -565,7 +565,7 @@ $(document).ready(function () { //上传数据 function updateGlobalCount() { $.ajax({ - url: './nahida.php', + url: '/api/count/nahida', method: 'POST', async: false, data: { localcount: thisTimeCounts }, @@ -588,7 +588,7 @@ function updateGlobalCount() { //首次访问网站的时候,立即获取 globalCounts并刷新 (页面加载完成后立即执行) document.addEventListener("DOMContentLoaded", function () { $.ajax({ - url: './nahida.php', + url: '/api/count/nahida', method: 'GET', dataType: 'json', headers: { @@ -614,7 +614,7 @@ document.addEventListener("DOMContentLoaded", function () { // 定时轮询后端获取 globalCounts setInterval(function () { $.ajax({ - url: './nahida.php', + url: '/api/count/nahida', method: 'GET', dataType: 'json', headers: { diff --git a/webs/config.php b/webs/config.php deleted file mode 100644 index 561ca5d..0000000 --- a/webs/config.php +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/webs/ys.sql b/webs/ys.sql deleted file mode 100644 index e69de29..0000000