mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
后台适配Trss
This commit is contained in:
parent
8aec804179
commit
880edace8a
5 changed files with 31 additions and 15 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { UserInfo, AddUser } from './user_data.js'
|
||||
import { randomString, getUserData, getMasterQQ } from '../../utils/common.js'
|
||||
import { randomString, getUserData, getMasterQQ, getUin } from '../../utils/common.js'
|
||||
import fs from 'fs'
|
||||
|
||||
async function User(fastify, options) {
|
||||
|
|
@ -8,7 +8,7 @@ async function User(fastify, options) {
|
|||
const body = request.body || {}
|
||||
if (body.qq && body.passwd) {
|
||||
const token = randomString(32)
|
||||
if (body.qq == Bot.uin && await redis.get('CHATGPT:ADMIN_PASSWD') == body.passwd) {
|
||||
if (body.qq == getUin() && await redis.get('CHATGPT:ADMIN_PASSWD') == body.passwd) {
|
||||
AddUser({ user: body.qq, token: token, autho: 'admin' })
|
||||
reply.setCookie('token', token, { path: '/' })
|
||||
reply.send({ login: true, autho: 'admin', token: token })
|
||||
|
|
@ -19,16 +19,16 @@ async function User(fastify, options) {
|
|||
reply.setCookie('token', token, { path: '/' })
|
||||
reply.send({ login: true, autho: 'user', token: token })
|
||||
} else {
|
||||
reply.send({ login: false, err: `用户名密码错误,如果忘记密码请私聊机器人输入 ${body.qq == Bot.uin ? '#修改管理密码' : '#修改用户密码'} 进行修改` })
|
||||
reply.send({ login: false, err: `用户名密码错误,如果忘记密码请私聊机器人输入 ${body.qq == getUin() ? '#修改管理密码' : '#修改用户密码'} 进行修改` })
|
||||
}
|
||||
}
|
||||
} else if (body.otp) {
|
||||
const token = randomString(32)
|
||||
const opt = await redis.get(`CHATGPT:SERVER_QUICK`)
|
||||
if (opt && body.otp == opt) {
|
||||
AddUser({ user: Bot.uin, token: token, autho: 'admin' })
|
||||
AddUser({ user: getUin(), token: token, autho: 'admin' })
|
||||
reply.setCookie('token', token, { path: '/' })
|
||||
reply.send({ login: true, autho: 'admin', token: token, user: Bot.uin })
|
||||
reply.send({ login: true, autho: 'admin', token: token, user: getUin() })
|
||||
} else {
|
||||
reply.send({ login: false, err: `快捷登录代码错误,请检查后重试` })
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue