From f4057ae956b9b3c6d0dcd96570eaa92e84e77541 Mon Sep 17 00:00:00 2001 From: aixianling Date: Wed, 26 Feb 2025 15:38:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(auth):=20=E6=B7=BB=E5=8A=A0=203xui=20?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 3xuiLogin.js 文件实现登录功能 - 添加 getCookie 函数用于获取登录 Cookie - 集成 HTTP 实例和表单数据处理 --- app.js | 1 - auth/3xuiLogin.js | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 auth/3xuiLogin.js diff --git a/app.js b/app.js index 4ac39d4..0520f73 100644 --- a/app.js +++ b/app.js @@ -53,7 +53,6 @@ const loadAPIRoutes = (baseDir = 'api', baseRoute = '/api') => { // 初始化扫描 scanDirectory(path.join(__dirname, baseDir), baseRoute); }; - // 公开路由 router.get("/public", (ctx) => { ctx.body = "Public content"; diff --git a/auth/3xuiLogin.js b/auth/3xuiLogin.js new file mode 100644 index 0000000..e71713f --- /dev/null +++ b/auth/3xuiLogin.js @@ -0,0 +1,19 @@ +const instance = require("../utils/http"); + +function getCookie() { + const formData = new FormData(); + formData.append("username", "lsw"); + formData.append("password", "lsw@2024"); + formData.append("loginSecret", "IEuVG4csTWLuaq3ysuUSHdwOcnoQRfScURwJVBjCMjRRpjVyYhWcgaHIJvU0SV4P"); + return instance + .post("/login", formData, { + maxRedirects: 0, // 禁止自动重定向以保留Cookie + withCredentials: true, // 确保携带凭证 + }) + .then((res) => { + const rawCookies = res.headers["set-cookie"] || []; + const cookies =["lang=zh-CN",rawCookies.at(-1)?.split(";")[0]].join(";"); + return cookies; + }); +} +module.exports = getCookie;