修复bug和旧代码清理 (#553)

* fix: 修复星火api上下文

* 将无星火ck的情况降低为warn

* feat: 添加星火设定自定义代码功能

* 修复星火api模式的一些问题

* 修复导出配置问题

* feat:添加工具箱快捷登录接口

* 添加工具箱快捷登录指令

* 阻止群聊使用快捷登录

* 添加Azure配置支持,修复重复的配置项冲突

* 移除旧版本渲染和新版本帮助

* 添加工具箱

* 更新工具箱替换原有后台

* 更新工具箱适配代码
This commit is contained in:
HalcyonAlcedo 2023-09-08 12:28:02 +08:00 committed by GitHub
parent 043b80ddd4
commit bf761c24da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
183 changed files with 1206 additions and 7675 deletions

View file

@ -1,5 +1,5 @@
import { UserInfo, AddUser } from './user_data.js'
import { randomString, getUserData } from '../../utils/common.js'
import { randomString, getUserData, getMasterQQ } from '../../utils/common.js'
import fs from 'fs'
async function User(fastify, options) {
@ -22,11 +22,34 @@ async function User(fastify, options) {
reply.send({ login: false, err: `用户名密码错误,如果忘记密码请私聊机器人输入 ${body.qq == Bot.uin ? '#修改管理密码' : '#修改用户密码'} 进行修改` })
}
}
} 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' })
reply.setCookie('token', token, { path: '/' })
reply.send({ login: true, autho: 'admin', token: token, user: Bot.uin })
} else {
reply.send({ login: false, err: `快捷登录代码错误,请检查后重试` })
}
} else {
reply.send({ login: false, err: '未输入用户名或密码' })
}
return reply
})
// 快速登录
fastify.post('/quick', async (request, reply) => {
const otp = randomString(6)
await redis.set(
`CHATGPT:SERVER_QUICK`,
otp,
{ EX: 60000 }
)
const master = (await getMasterQQ())[0]
Bot.sendPrivateMsg(master, `收到工具箱快捷登录请求1分钟内有效${otp}`, false)
reply.send({ state: true })
return reply
})
// 检查用户是否存在
fastify.post('/verify', async (request, reply) => {
const token = request.cookies.token || request.body?.token || 'unknown'
@ -41,7 +64,7 @@ async function User(fastify, options) {
verify: true,
user: user.user,
autho: user.autho,
version: 10010,
version: 10016,
})
return reply
})

View file

@ -3,22 +3,17 @@ import fs from 'fs'
async function routes(fastify, options) {
fastify.get('/page/*', async (request, reply) => {
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/index.html')
reply.type('text/html').send(stream)
return reply
})
fastify.get('/help/*', async (request, reply) => {
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/index.html')
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/page.html')
reply.type('text/html').send(stream)
return reply
})
fastify.get('/version', async (request, reply) => {
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/index.html')
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/page.html')
reply.type('text/html').send(stream)
return reply
})
fastify.get('/auth/*', async (request, reply) => {
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/index.html')
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/page.html')
reply.type('text/html').send(stream)
return reply
})
@ -28,7 +23,7 @@ async function routes(fastify, options) {
if (!user) {
reply.redirect(301, '/auth/login')
}
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/index.html')
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/page.html')
reply.type('text/html').send(stream)
return reply
})
@ -41,7 +36,7 @@ async function routes(fastify, options) {
if (user.autho === 'admin') {
reply.redirect(301, '/admin/settings')
}
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/index.html')
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/page.html')
reply.type('text/html').send(stream)
return reply
})
@ -51,7 +46,7 @@ async function routes(fastify, options) {
if (!user || user.autho != 'admin') {
reply.redirect(301, '/admin/')
}
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/index.html')
const stream = fs.createReadStream('plugins/chatgpt-plugin/server/static/page.html')
reply.type('text/html').send(stream)
return reply
})