From ab65a58552601ec9ac0ffd66e0e67090afbcafe4 Mon Sep 17 00:00:00 2001 From: mattuy Date: Sun, 7 Nov 2021 23:31:58 +0800 Subject: [PATCH] =?UTF-8?q?server:=20=E4=BF=AE=E6=94=B9=E9=89=B4=E6=9D=83?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=A4=B4=E5=AD=97=E6=AE=B5=EF=BC=8C=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E4=B8=8B=E5=88=92=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/{src => }/options.example.json | 8 ++--- packages/server/src/index.js | 31 ------------------- packages/server/src/socket.js | 7 +++-- 3 files changed, 9 insertions(+), 37 deletions(-) rename packages/server/{src => }/options.example.json (53%) diff --git a/packages/server/src/options.example.json b/packages/server/options.example.json similarity index 53% rename from packages/server/src/options.example.json rename to packages/server/options.example.json index 46be294..2f5730e 100644 --- a/packages/server/src/options.example.json +++ b/packages/server/options.example.json @@ -3,13 +3,13 @@ "dataDir": "/home/master/desktop", "serve": true, "httpHost": "localhost", - "httpPort": 9200, + "httpPort": 8094, "debugMode": false, - "baseUrl": "http://localhost:9200", + "baseUrl": "http://localhost:8094", "appCode": { - "mattuy-laptop": "iasdjfkwe3ds-qw3rjkwjfda8" + "debug": "debug" }, "appAuthHash": { - "mattuy-laptop": "b9c901e0ee98486361b2e5461442af3f3863961f" + "debug": "" } } diff --git a/packages/server/src/index.js b/packages/server/src/index.js index 80f1c23..70e952e 100644 --- a/packages/server/src/index.js +++ b/packages/server/src/index.js @@ -61,34 +61,3 @@ async function start() { } start(); - -// let sessionData = JSON.parse( -// fs.readFileSync("/home/master/desktop/session.json"), -// { -// encoding: "utf-8", -// } -// ); -// const W = require("wechat4u"); -// const bot = new W(sessionData); -// bot.on("uuid", (uuid) => { -// qrCode.generate("https://login.weixin.qq.com/l/" + uuid, { -// small: true, -// }); -// }); - -// bot.on("login", async () => { -// console.log("logged in"); -// fs.writeFileSync( -// "/home/master/desktop/session.json", -// JSON.stringify(bot.botData) -// ); -// const { mediaId } = await bot.uploadMedia( -// fs.createReadStream("/home/master/desktop/q.jpg"), -// undefined, -// "filehelper" -// ); -// bot.sendPic(mediaId, "filehelper").then((rse) => { -// console.log(rse); -// }); -// }); -// bot.restart(); diff --git a/packages/server/src/socket.js b/packages/server/src/socket.js index ab43f8c..30f3417 100644 --- a/packages/server/src/socket.js +++ b/packages/server/src/socket.js @@ -40,7 +40,10 @@ io.use((socket, next) => { if (!appCode || appCode !== auth.appCode) { return next(Error("认证失败")); } - if (textSHA1(auth.passphrase) !== config.appAuthHash[appName]) { + if ( + config.appAuthHash[appName] && + textSHA1(auth.passphrase) !== config.appAuthHash[appName] + ) { return next(Error("口令错误")); } if (activeSessions.has(socket.handshake.auth.sessionID)) { @@ -268,7 +271,7 @@ router.get("/session/:sessionID/media/:composedID/:filename", (ctx, next) => { /** 上传文件 */ router.post("/upload_file", async (ctx, next) => { - if (!activeSessions.has(ctx.request.headers.session_id)) { + if (!activeSessions.has(ctx.request.headers['sid'])) { ctx.throw(401); } const filename = dayjs().format("YYYYMMDD_") + String(Math.random()).slice(2);