From f038b78c494012b142dd83e0c8fb6fdea87b5c26 Mon Sep 17 00:00:00 2001 From: lyz05 <294068487@qq.com> Date: Wed, 10 Jan 2024 23:30:49 +0800 Subject: [PATCH] fix: log config --- app.js | 4 ++-- routes/airportsub.js | 6 +++--- routes/danmaku.js | 4 ++-- utils/leancloud.js | 16 ++++++++-------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app.js b/app.js index 83ef865..dacabdb 100644 --- a/app.js +++ b/app.js @@ -23,7 +23,7 @@ app.set("trust proxy", true); app.use(logger("dev")); app.use(express.json()); -app.use(express.urlencoded({ extended: false })); +app.use(express.urlencoded({ extended: false, validate: { trustProxy: false } })); app.use(cookieParser()); // 加载静态资源 app.use(express.static(path.join(__dirname, "public"))); @@ -32,7 +32,7 @@ app.use("/assets", [ express.static(__dirname + "/node_modules/bootstrap/dist/"), express.static(__dirname + "/node_modules/axios/dist/"), ]); -app.use("/upload", express.static(__dirname + "/upload")); +// app.use("/upload", express.static(__dirname + "/upload")); // 加载路由 app.use("/", danmakuRouter); diff --git a/routes/airportsub.js b/routes/airportsub.js index e748898..baf6fb7 100644 --- a/routes/airportsub.js +++ b/routes/airportsub.js @@ -4,9 +4,9 @@ const leancloud = require("../utils/leancloud"); /* GET users listing. */ router.get("/", async function (req, res) { - leancloud.add("SubAccess", { - ip: req.ip, - ua: req.headers["user-agent"], + await leancloud.add("SubAccess", { + remoteIP: req.ip, + UA: req.headers["user-agent"], user: req.query.user, ctype: req.query.ctype }); diff --git a/routes/danmaku.js b/routes/danmaku.js index e40b190..e7b8651 100644 --- a/routes/danmaku.js +++ b/routes/danmaku.js @@ -63,7 +63,7 @@ async function build_response(url, req) { console.log(e); let err = JSON.stringify(e, Object.getOwnPropertyNames(e)); err = JSON.parse(err); - leancloud.add("DanmakuError", { + await leancloud.add("DanmakuError", { ip: req.ip, url, err @@ -108,7 +108,7 @@ async function index(req, res) { /* GET home page. */ router.get("/", apiLimiter, async function (req, res) { - leancloud.add("DanmakuAccess", { + await leancloud.add("DanmakuAccess", { remoteIP: req.ip, url: req.query.url, UA: req.headers["user-agent"] diff --git a/utils/leancloud.js b/utils/leancloud.js index 05960b4..72b8e08 100644 --- a/utils/leancloud.js +++ b/utils/leancloud.js @@ -47,19 +47,19 @@ async function danmakuQuery(date, ip) { return await query.count(); } -function add(className, obj) { +async function add(className, obj) { if (!AV) return; - if (obj.ip || obj.remoteIP) - obj.ipCountry = getipCountry(obj.ip || obj.remoteIP); + if (obj.remoteIP) + obj.ipCountry = getipCountry(obj.remoteIP); const classInstance = AV.Object.extend(className); const record = new classInstance(); for (const key of Object.keys(obj)) { record.set(key, obj[key]); } - record.save().then((obj) => { - // 成功保存之后,执行其他逻辑 - console.log(`${className}添加一条记录。objectId:${obj.id}`); - }); + console.log(record.attributes); + const o = await record.save() + // 成功保存之后,执行其他逻辑 + console.log(`${className}添加一条记录。objectId:${o.id}`); } function getipCountry(ip) { @@ -67,7 +67,7 @@ function getipCountry(ip) { const info = qqwry.searchIP(ip); return info.Country + " " + info.Area; } catch (e) { - return null; + return ""; } }