mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
对后台更新 (#683)
* fix: 修复星火api上下文 * 将无星火ck的情况降低为warn * feat: 添加星火设定自定义代码功能 * 修复星火api模式的一些问题 * 修复导出配置问题 * feat:添加工具箱快捷登录接口 * 添加工具箱快捷登录指令 * 阻止群聊使用快捷登录 * 添加Azure配置支持,修复重复的配置项冲突 * 移除旧版本渲染和新版本帮助 * 添加工具箱 * 更新工具箱替换原有后台 * 更新工具箱适配代码 * 后台适配Trss * 修复trss不支持sendPrivateMsg的问题 * 优化路由 * 修复路由 * 适配其他uin * 添加bing第三方绘图 * 修复bing绘图第三方调用错误 * 添加bing第三方绘图采样配置 * 修复错误 * 添加bing第三方绘图图片大小配置 * 修复视图错误 * 使用ap替换第三方绘图 * 适配trss * server 适配trss * 修复错误的后台版本更新 * 添加锅巴用户数据 * 修复server初始化消息错误 * 添加锅巴插件适配 * 更新后台页面 * 添加锅巴代理接口 * 优化锅巴接口代理 * 修复锅巴代理参数 * 删除调试信息 * 修复headers * 更新后台锅巴插件支持 * 适配星火v3 * 适配星火v3 * 修复星火domain错误 * 修复更新后trss无法快捷登陆面板问题 * 奇怪的错误,忽略提示不影响使用 * 添加后台配置项 * 添加后台星火v3.5模式选项 * 添加后台缺少的部分配置项 * 增加后台对缺少的锅巴配置自动读取,将后台登陆信息添加到redis
This commit is contained in:
parent
7bbe1a9db1
commit
b431794497
5 changed files with 184 additions and 9 deletions
|
|
@ -1,7 +1,23 @@
|
|||
import { UserInfo } from './user_data.js'
|
||||
import { supportGuoba } from '../../guoba.support.js'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
function getAttributeValues(obj, attributeName, results = []) {
|
||||
if (Array.isArray(obj)) {
|
||||
obj.forEach(item => getAttributeValues(item, attributeName, results));
|
||||
} else if (typeof obj === 'object' && obj !== null) {
|
||||
Object.keys(obj).forEach(key => {
|
||||
if (key === attributeName) {
|
||||
results.push(obj[key]);
|
||||
} else if (typeof obj[key] === 'object') {
|
||||
getAttributeValues(obj[key], attributeName, results);
|
||||
}
|
||||
});
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
async function SettingView(fastify, options) {
|
||||
// 获取配置视图
|
||||
fastify.post('/settingView', async (request, reply) => {
|
||||
|
|
@ -11,7 +27,56 @@ async function SettingView(fastify, options) {
|
|||
reply.send({ err: '未登录' })
|
||||
} else if (user.autho === 'admin') {
|
||||
const filepath = path.join('plugins/chatgpt-plugin/resources/view', 'setting_view.json')
|
||||
const configView = JSON.parse(fs.readFileSync(filepath, 'utf8'))
|
||||
let configView = JSON.parse(fs.readFileSync(filepath, 'utf8'))
|
||||
|
||||
// 从锅巴配置获取额外配置视图
|
||||
const guoba = supportGuoba()
|
||||
const guobaConfig = guoba.configInfo.schemas
|
||||
const viewDataList = getAttributeValues(configView, 'data')
|
||||
const guobaDataList = getAttributeValues(guobaConfig, 'field')
|
||||
const otherDataList = guobaDataList.filter(item => !viewDataList.includes(item))
|
||||
const otherData = guobaConfig.filter(item => otherDataList.includes(item.field))
|
||||
// 转换视图
|
||||
if (otherData.length > 0) {
|
||||
let otherView = []
|
||||
for (const data of otherData) {
|
||||
let view = {
|
||||
'label': data.label,
|
||||
'placeholder': data.bottomHelpMessage || undefined,
|
||||
'data': data.field,
|
||||
}
|
||||
switch (data.component) {
|
||||
case 'Input':
|
||||
view.type = 'text'
|
||||
break
|
||||
case 'Switch':
|
||||
view.type = 'check'
|
||||
break
|
||||
case 'InputNumber':
|
||||
view.type = 'number'
|
||||
break
|
||||
case 'InputPassword':
|
||||
view.type = 'password'
|
||||
break
|
||||
case 'InputTextArea':
|
||||
view.type = 'textarea'
|
||||
break
|
||||
case 'Select':
|
||||
view.type = 'textarea'
|
||||
view.items = data.componentProps.options
|
||||
break
|
||||
default:
|
||||
continue
|
||||
}
|
||||
otherView.push(view)
|
||||
}
|
||||
configView.push({
|
||||
"id": "OtherSettings",
|
||||
"title": "其他设置",
|
||||
"view": otherView
|
||||
})
|
||||
}
|
||||
|
||||
reply.send(configView)
|
||||
} else {
|
||||
reply.send({ err: '权限不足' })
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@ async function User (fastify, options) {
|
|||
const token = randomString(32)
|
||||
if (body.qq == getUin() && await redis.get('CHATGPT:ADMIN_PASSWD') == body.passwd) {
|
||||
const guobaToken = await guobaLoginService.signToken(body.qq)
|
||||
AddUser({ user: body.qq, token, autho: 'admin' })
|
||||
await AddUser({ user: body.qq, token, autho: 'admin' })
|
||||
reply.setCookie('token', token, { path: '/' })
|
||||
reply.send({ login: true, autho: 'admin', token, guobaToken, guoba: guobaAPI })
|
||||
} else {
|
||||
const user = await getUserData(body.qq)
|
||||
if (user.passwd != '' && user.passwd === body.passwd) {
|
||||
AddUser({ user: body.qq, token, autho: 'user' })
|
||||
await AddUser({ user: body.qq, token, autho: 'user' })
|
||||
reply.setCookie('token', token, { path: '/' })
|
||||
reply.send({ login: true, autho: 'user', token })
|
||||
} else {
|
||||
|
|
@ -43,7 +43,7 @@ async function User (fastify, options) {
|
|||
const opt = await redis.get('CHATGPT:SERVER_QUICK')
|
||||
if (opt && body.otp == opt) {
|
||||
const guobaToken = await guobaLoginService.signToken(getUin())
|
||||
AddUser({ user: getUin(), token, autho: 'admin' })
|
||||
await AddUser({ user: getUin(), token, autho: 'admin' })
|
||||
reply.setCookie('token', token, { path: '/' })
|
||||
reply.send({ login: true, autho: 'admin', token, user: getUin(), guobaToken, guoba: guobaAPI })
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ export function GetUser(user) {
|
|||
return users.user.find(user => user === user)
|
||||
}
|
||||
// 添加用户token
|
||||
export function AddUser(data) {
|
||||
export async function AddUser(data) {
|
||||
const userIndex = users.user.findIndex(user => user === data.user)
|
||||
if (userIndex >= 0) {
|
||||
users.user[userIndex].token.push(data.token)
|
||||
|
|
@ -38,4 +38,8 @@ export function AddUser(data) {
|
|||
tiem: new Date()
|
||||
})
|
||||
}
|
||||
await redis.set('CHATGPT:SERVER_USER', JSON.stringify(users))
|
||||
}
|
||||
export async function ReplaceUsers() {
|
||||
users = JSON.parse(await redis.get('CHATGPT:SERVER_USER') || '{"user": []}')
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue