chatgpt-plugin/server/modules/setting_view.js
HalcyonAlcedo b431794497
对后台更新 (#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
2024-05-05 14:09:39 +08:00

88 lines
No EOL
3.3 KiB
JavaScript

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) => {
const token = request.cookies.token || request.body?.token || 'unknown'
let user = UserInfo(token)
if (!user) {
reply.send({ err: '未登录' })
} else if (user.autho === 'admin') {
const filepath = path.join('plugins/chatgpt-plugin/resources/view', 'setting_view.json')
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: '权限不足' })
}
return reply
})
}
export default SettingView