mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 05:47:11 +00:00
适配Trss (#575)
* fix: 修复星火api上下文 * 将无星火ck的情况降低为warn * feat: 添加星火设定自定义代码功能 * 修复星火api模式的一些问题 * 修复导出配置问题 * feat:添加工具箱快捷登录接口 * 添加工具箱快捷登录指令 * 阻止群聊使用快捷登录 * 添加Azure配置支持,修复重复的配置项冲突 * 移除旧版本渲染和新版本帮助 * 添加工具箱 * 更新工具箱替换原有后台 * 更新工具箱适配代码 * 后台适配Trss * 修复trss不支持sendPrivateMsg的问题 * 优化路由 * 修复路由 * 适配其他uin
This commit is contained in:
parent
64f2699b22
commit
0f9c8a7abe
10 changed files with 73 additions and 37 deletions
|
|
@ -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: `快捷登录代码错误,请检查后重试` })
|
||||
}
|
||||
|
|
@ -46,7 +46,11 @@ async function User(fastify, options) {
|
|||
{ EX: 60000 }
|
||||
)
|
||||
const master = (await getMasterQQ())[0]
|
||||
Bot.sendPrivateMsg(master, `收到工具箱快捷登录请求,1分钟内有效:${otp}`, false)
|
||||
if (Array.isArray(Bot.uin)) {
|
||||
Bot.pickFriend(master).sendMsg(`收到工具箱快捷登录请求,1分钟内有效:${otp}`)
|
||||
} else {
|
||||
Bot.sendPrivateMsg(master, `收到工具箱快捷登录请求,1分钟内有效:${otp}`, false)
|
||||
}
|
||||
reply.send({ state: true })
|
||||
return reply
|
||||
})
|
||||
|
|
|
|||
|
|
@ -50,6 +50,14 @@ async function routes(fastify, options) {
|
|||
reply.type('text/html').send(stream)
|
||||
return reply
|
||||
})
|
||||
fastify.setNotFoundHandler((request, reply) => {
|
||||
if (request.method == 'GET') {
|
||||
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/index.html')
|
||||
reply.type('text/html').send(stream)
|
||||
} else {
|
||||
reply.code(404).send(new Error('Not Found'))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default routes
|
||||
Loading…
Add table
Add a link
Reference in a new issue