后台适配Trss

This commit is contained in:
zyc404 2023-10-08 18:16:50 +08:00
parent 8aec804179
commit 880edace8a
5 changed files with 31 additions and 15 deletions

View file

@ -12,7 +12,7 @@ import websocketclient from 'ws'
import { Config } from '../utils/config.js'
import { UserInfo, GetUser, AddUser } from './modules/user_data.js'
import { getPublicIP, getUserData, getMasterQQ, randomString } from '../utils/common.js'
import { getPublicIP, getUserData, getMasterQQ, randomString, getUin } from '../utils/common.js'
import webRoute from './modules/web_route.js'
import webUser from './modules/user.js'
@ -107,7 +107,7 @@ async function mediaLink() {
ws.on('open', () => {
ws.send(JSON.stringify({
command: 'register',
region: Bot.uin,
region: getUin(),
type: 'server',
}))
})
@ -128,30 +128,30 @@ async function mediaLink() {
const user = UserInfo(data.token)
if (user) {
ws.login = true
ws.send(JSON.stringify({ command: data.command, state: true, region: Bot.uin, type: 'server' }))
ws.send(JSON.stringify({ command: data.command, state: true, region: getUin(), type: 'server' }))
} else {
ws.send(JSON.stringify({ command: data.command, state: false, error: '权限验证失败', region: Bot.uin, type: 'server' }))
ws.send(JSON.stringify({ command: data.command, state: false, error: '权限验证失败', region: getUin(), type: 'server' }))
}
}
break
case 'post_login':
if (data.qq && data.passwd) {
const token = randomString(32)
if (data.qq == Bot.uin && await redis.get('CHATGPT:ADMIN_PASSWD') == data.passwd) {
if (data.qq == getUin() && await redis.get('CHATGPT:ADMIN_PASSWD') == data.passwd) {
AddUser({ user: data.qq, token: token, autho: 'admin' })
ws.send(JSON.stringify({ command: data.command, state: true, autho: 'admin', token: token, region: Bot.uin, type: 'server' }))
ws.send(JSON.stringify({ command: data.command, state: true, autho: 'admin', token: token, region: getUin(), type: 'server' }))
} else {
const user = await getUserData(data.qq)
if (user.passwd != '' && user.passwd === data.passwd) {
AddUser({ user: data.qq, token: token, autho: 'user' })
ws.send(JSON.stringify({ command: data.command, state: true, autho: 'user', token: token, region: Bot.uin, type: 'server' }))
ws.send(JSON.stringify({ command: data.command, state: true, autho: 'user', token: token, region: getUin(), type: 'server' }))
} else {
ws.send(JSON.stringify({ command: data.command, state: false, error: `用户名密码错误,如果忘记密码请私聊机器人输入 ${data.qq == Bot.uin ? '#修改管理密码' : '#修改用户密码'} 进行修改`, region: Bot.uin, type: 'server' }))
ws.send(JSON.stringify({ command: data.command, state: false, error: `用户名密码错误,如果忘记密码请私聊机器人输入 ${data.qq == getUin() ? '#修改管理密码' : '#修改用户密码'} 进行修改`, region: getUin(), type: 'server' }))
}
}
} else {
ws.send(JSON.stringify({ command: data.command, state: false, error: '未输入用户名或密码', region: Bot.uin, type: 'server' }))
ws.send(JSON.stringify({ command: data.command, state: false, error: '未输入用户名或密码', region: getUin(), type: 'server' }))
}
break
case 'post_command':
@ -163,7 +163,7 @@ async function mediaLink() {
const response = await fetch(`http://localhost:${Config.serverPort || 3321}${data.postPath}`, fetchOptions)
if (response.ok) {
const json = await response.json()
ws.send(JSON.stringify({ command: data.command, state: true, region: Bot.uin, type: 'server', path: data.postPath, data: json }))
ws.send(JSON.stringify({ command: data.command, state: true, region: getUin(), type: 'server', path: data.postPath, data: json }))
}
break
}