mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
feat: 适配远程渲染服务器,优化Live2D (#463)
* 修复后台API反代地址未能正确显示的问题 * 更新渲染页面配置 * 添加个人聊天模式配置 * 将用户数据获取改到common中 * 修复错误的渲染页面参数 * 修复bug * 添加Live2D * 修复渲染页面错误 * 修复渲染传入值 * 更新渲染 * 修复图表渲染bug * 调整live2d模型大小 * 修复live2d无法关闭问题 * 修复错误的传值 * 修复ai命名 * 更新渲染 * 添加用户独立设定 * 更新渲染配置适配个人设置 * 修复合并导致的渲染文件异常删除 * 修复用户数据缺失问题 * 修复旧版本数据缺失问题 * 修复bing参数不存在问题,兼容miao的截图 * 修复受限token重试时不被排除的问题 * 修复个人模式下结束对话的模式错误 * 更新渲染页面,将预览版转为正式版 * 修复传统渲染无法调用截图功能的问题 * 文字模式也进行一次缓存 * 更新README * Update README.md * 更新渲染 * 更新渲染页面 * 添加版本信息 * 遗漏参数 * 丢失引用 * 补充路由 * 添加云转码功能 * 判断node-silk是否正常合成 * 云转码提示 * 修复图片渲染出错 * 云转码支持发送Buffer * 添加云转码模式支持 * 更新描述 * 更新后台渲染页面 * 更新配置 * 更新渲染页面 * 添加云渲染 * 修复错误的接口调用 * 修复遗漏的数据转换 * 修复获取的图片数据异常问题 * 更新后台配置 * 更新渲染页面 * 修复云渲染访问地址错误 * 更新渲染页面 * 修复遗漏的模型文件 * 修复live2d问题 * 更新live2d以及相关配置 * 修复遗漏的数据参数 * 修复新live2d情况下云渲染错误的问题 * 适配云渲染1.1.2等待参数 * 添加云服务api检查 * 更新渲染页面 * 添加live2d加载检测 * 修复错误的属性判断 * 添加云渲染DPR * 更新sydney支持内容生成 * 修改文件模式语音转码接收模式 * 添加云转码时recordUrl检查 * 更新后台配置项 * 修复错误的文本描述 * 更新后台页面 * 添加全局对话模式设置,更新后台面板 * 添加第三方渲染服务适配 * 修复第三方服务器live2d加载导致的渲染失败问题 * 修复后台地址无法实时保存的问题 * 添加live2d模型透明度设置 * 合并更新 * 更新渲染页面 * 更新渲染页面 * 使dpr对本地渲染也生效 * 更新渲染页面 * 添加网页截图功能 * 添加后台配置项 * 添加配置导出和导入功能 * 运行通过参数传递用户token * 登录时将token作为参数返回 * 修复错误 * 添加密码修改和用户删除接口 * 修正密码比对 * 修复user错误 * 优化数据保存时的返回值 * 添加系统额外服务检查api * 添加AccessToken配置 --------- Co-authored-by: ikechan8370 <geyinchibuaa@gmail.com>
This commit is contained in:
parent
508beaece3
commit
317283218a
23 changed files with 398 additions and 141 deletions
156
server/index.js
156
server/index.js
|
|
@ -85,7 +85,7 @@ export async function createServer() {
|
|||
reply.type('text/html').send(stream)
|
||||
})
|
||||
await server.get('/admin*', (request, reply) => {
|
||||
const token = request.cookies.token || 'unknown'
|
||||
const token = request.cookies.token || request.body?.token || 'unknown'
|
||||
const user = usertoken.find(user => user.token === token)
|
||||
if (!user) {
|
||||
reply.redirect(301, '/auth/login')
|
||||
|
|
@ -94,7 +94,7 @@ export async function createServer() {
|
|||
reply.type('text/html').send(stream)
|
||||
})
|
||||
await server.get('/admin/dashboard', (request, reply) => {
|
||||
const token = request.cookies.token || 'unknown'
|
||||
const token = request.cookies.token || request.body?.token || 'unknown'
|
||||
const user = usertoken.find(user => user.token === token)
|
||||
if (!user) {
|
||||
reply.redirect(301, '/auth/login')
|
||||
|
|
@ -106,7 +106,7 @@ export async function createServer() {
|
|||
reply.type('text/html').send(stream)
|
||||
})
|
||||
await server.get('/admin/settings', (request, reply) => {
|
||||
const token = request.cookies.token || 'unknown'
|
||||
const token = request.cookies.token || request.body?.token || 'unknown'
|
||||
const user = usertoken.find(user => user.token === token)
|
||||
if (!user || user.autho != 'admin') {
|
||||
reply.redirect(301, '/admin/')
|
||||
|
|
@ -122,13 +122,13 @@ export async function createServer() {
|
|||
if (body.qq == Bot.uin && await redis.get('CHATGPT:ADMIN_PASSWD') == body.passwd) {
|
||||
usertoken.push({ user: body.qq, token, autho: 'admin' })
|
||||
reply.setCookie('token', token, { path: '/' })
|
||||
reply.send({ login: true, autho: 'admin' })
|
||||
reply.send({ login: true, autho: 'admin', token: token })
|
||||
} else {
|
||||
const user = await getUserData(body.qq)
|
||||
if (user.passwd != '' && user.passwd === body.passwd) {
|
||||
usertoken.push({ user: body.qq, token, autho: 'user' })
|
||||
reply.setCookie('token', token, { path: '/' })
|
||||
reply.send({ login: true, autho: 'user' })
|
||||
reply.send({ login: true, autho: 'user', token: token })
|
||||
} else {
|
||||
reply.send({ login: false, err: `用户名密码错误,如果忘记密码请私聊机器人输入 ${body.qq == Bot.uin ? '#修改管理密码' : '#修改用户密码'} 进行修改` })
|
||||
}
|
||||
|
|
@ -137,6 +137,22 @@ export async function createServer() {
|
|||
reply.send({ login: false, err: '未输入用户名或密码' })
|
||||
}
|
||||
})
|
||||
// 检查用户是否存在
|
||||
server.post('/verify', async (request, reply) => {
|
||||
const token = request.cookies.token || request.body?.token || 'unknown'
|
||||
let user = usertoken.find(user => user.token === token)
|
||||
if (!user || token === 'unknown') {
|
||||
reply.send({
|
||||
verify: false,
|
||||
})
|
||||
return
|
||||
}
|
||||
reply.send({
|
||||
verify: true,
|
||||
user: user.user,
|
||||
autho: user.autho
|
||||
})
|
||||
})
|
||||
// 页面数据获取
|
||||
server.post('/page', async (request, reply) => {
|
||||
const body = request.body || {}
|
||||
|
|
@ -217,7 +233,9 @@ export async function createServer() {
|
|||
x: Config.live2dOption_positionX,
|
||||
y: Config.live2dOption_positionY
|
||||
},
|
||||
rotation :Config.live2dOption_rotation,
|
||||
rotation: Config.live2dOption_rotation,
|
||||
alpha: Config.live2dOption_alpha,
|
||||
dpr: Config.cloudDPR
|
||||
},
|
||||
time: new Date()
|
||||
}
|
||||
|
|
@ -248,7 +266,7 @@ export async function createServer() {
|
|||
|
||||
// 获取用户数据
|
||||
server.post('/userData', async (request, reply) => {
|
||||
const token = request.cookies.token || 'unknown'
|
||||
const token = request.cookies.token || request.body?.token || 'unknown'
|
||||
let user = usertoken.find(user => user.token === token)
|
||||
if (!user) user = { user: '' }
|
||||
const userData = await getUserData(user.user)
|
||||
|
|
@ -264,9 +282,67 @@ export async function createServer() {
|
|||
})
|
||||
})
|
||||
|
||||
// 删除用户
|
||||
server.post('/deleteUser', async (request, reply) => {
|
||||
const token = request.cookies.token || request.body?.token || 'unknown'
|
||||
let user = usertoken.find(user => user.token === token)
|
||||
if (!user || user === 'unknown') {
|
||||
reply.send({ state: false, error: '无效token' })
|
||||
return
|
||||
}
|
||||
const filepath = `resources/ChatGPTCache/user/${user.user}.json`
|
||||
fs.unlinkSync(filepath)
|
||||
reply.send({ state: true })
|
||||
})
|
||||
// 修改密码
|
||||
server.post('/changePassword', async (request, reply) => {
|
||||
const token = request.cookies.token || request.body?.token || 'unknown'
|
||||
let user = usertoken.find(user => user.token === token)
|
||||
if (!user || user === 'unknown') {
|
||||
reply.send({ state: false, error: '无效的用户信息' })
|
||||
return
|
||||
}
|
||||
const userData = await getUserData(user.user)
|
||||
const body = request.body || {}
|
||||
if (!body.newPasswd) {
|
||||
reply.send({ state: false, error: '无效参数' })
|
||||
return
|
||||
}
|
||||
if (body.passwd && body.passwd != userData.passwd) {
|
||||
reply.send({ state: false, error: '原始密码错误' })
|
||||
return
|
||||
}
|
||||
if (user.autho === 'admin') {
|
||||
await redis.set('CHATGPT:ADMIN_PASSWD', body.newPasswd)
|
||||
} else if (user.autho === 'user') {
|
||||
const dir = 'resources/ChatGPTCache/user'
|
||||
const filename = `${user.user}.json`
|
||||
const filepath = path.join(dir, filename)
|
||||
fs.mkdirSync(dir, { recursive: true })
|
||||
if (fs.existsSync(filepath)) {
|
||||
fs.readFile(filepath, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
return
|
||||
}
|
||||
const config = JSON.parse(data)
|
||||
config.passwd = body.newPasswd
|
||||
fs.writeFile(filepath, JSON.stringify(config), 'utf8', (err) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
reply.send({ state: false, error: '错误的用户数据' })
|
||||
return
|
||||
}
|
||||
}
|
||||
reply.send({ state: true })
|
||||
})
|
||||
// 清除缓存数据
|
||||
server.post('/cleanCache', async (request, reply) => {
|
||||
const token = request.cookies.token || 'unknown'
|
||||
const token = request.cookies.token || request.body?.token || 'unknown'
|
||||
let user = usertoken.find(user => user.token === token)
|
||||
if (!user) user = { user: '' }
|
||||
const userData = await getUserData(user.user)
|
||||
|
|
@ -283,7 +359,7 @@ export async function createServer() {
|
|||
|
||||
// 获取系统参数
|
||||
server.post('/sysconfig', async (request, reply) => {
|
||||
const token = request.cookies.token || 'unknown'
|
||||
const token = request.cookies.token || request.body?.token || 'unknown'
|
||||
const user = usertoken.find(user => user.token === token)
|
||||
if (!user) {
|
||||
reply.send({ err: '未登录' })
|
||||
|
|
@ -302,6 +378,9 @@ export async function createServer() {
|
|||
if (await redis.exists('CHATGPT:USE') != 0) {
|
||||
redisConfig.useMode = await redis.get('CHATGPT:USE')
|
||||
}
|
||||
if (await redis.exists('CHATGPT:?') != 0) {
|
||||
redisConfig.openAiPlatformAccessToken = await redis.get('CHATGPT:TOKEN')
|
||||
}
|
||||
reply.send({
|
||||
chatConfig: Config,
|
||||
redisConfig
|
||||
|
|
@ -325,30 +404,31 @@ export async function createServer() {
|
|||
|
||||
// 设置系统参数
|
||||
server.post('/saveconfig', async (request, reply) => {
|
||||
const token = request.cookies.token || 'unknown'
|
||||
const token = request.cookies.token || request.body?.token || 'unknown'
|
||||
const user = usertoken.find(user => user.token === token)
|
||||
const body = request.body || {}
|
||||
let changeConfig = []
|
||||
if (!user) {
|
||||
reply.send({ err: '未登录' })
|
||||
reply.send({ state: false, error: '未登录' })
|
||||
} else if (user.autho === 'admin') {
|
||||
const chatdata = body.chatConfig || {}
|
||||
for (let [keyPath, value] of Object.entries(chatdata)) {
|
||||
if (keyPath === 'blockWords' || keyPath === 'promptBlockWords' || keyPath === 'initiativeChatGroups') { value = value.toString().split(/[,,;;\|]/) }
|
||||
if (Config[keyPath] != value) {
|
||||
//检查云服务api
|
||||
if(keyPath === 'cloudTranscode') {
|
||||
if (keyPath === 'cloudTranscode') {
|
||||
const referer = request.headers.referer;
|
||||
const origin = referer.match(/(https?:\/\/[^/]+)/)[1];
|
||||
const checkCloud = await fetch(`${value}/check`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
url: origin
|
||||
const checkCloud = await fetch(`${value}/check`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
url: origin
|
||||
})
|
||||
})
|
||||
})
|
||||
if (checkCloud.ok) {
|
||||
const checkCloudData = await checkCloud.json()
|
||||
if (checkCloudData.state != 'ok') {
|
||||
|
|
@ -356,7 +436,12 @@ export async function createServer() {
|
|||
}
|
||||
} else value = ''
|
||||
}
|
||||
Config[keyPath] = value
|
||||
changeConfig.push({
|
||||
item: keyPath,
|
||||
old: Config[keyPath],
|
||||
new: value
|
||||
})
|
||||
Config[keyPath] = value
|
||||
}
|
||||
}
|
||||
const redisConfig = body.redisConfig || {}
|
||||
|
|
@ -369,6 +454,11 @@ export async function createServer() {
|
|||
if (redisConfig.useMode != null) {
|
||||
await redis.set('CHATGPT:USE', redisConfig.useMode)
|
||||
}
|
||||
if (redisConfig.openAiPlatformAccessToken != null) {
|
||||
await redis.set('CHATGPT:TOKEN', redisConfig.openAiPlatformAccessToken)
|
||||
}
|
||||
|
||||
reply.send({ change: changeConfig, state: true })
|
||||
} else {
|
||||
if (body.userSetting) {
|
||||
await redis.set(`CHATGPT:USER:${user.user}`, JSON.stringify(body.userSetting))
|
||||
|
|
@ -383,9 +473,31 @@ export async function createServer() {
|
|||
}
|
||||
await setUserData(user.user, temp_userData)
|
||||
}
|
||||
reply.send({ state: true })
|
||||
}
|
||||
})
|
||||
|
||||
// 系统服务测试
|
||||
server.post('/serverTest', async (request, reply) => {
|
||||
let serverState = {
|
||||
cache: false,
|
||||
cloud: false
|
||||
}
|
||||
if (Config.cacheUrl) {
|
||||
const checkCacheUrl = await fetch(Config.cacheUrl, { method: 'GET' })
|
||||
if (checkCacheUrl.ok) {
|
||||
serverState.cache = true
|
||||
}
|
||||
}
|
||||
if (Config.cloudTranscode) {
|
||||
const checkCheckCloud= await fetch(Config.cloudTranscode, { method: 'GET' })
|
||||
if (checkCheckCloud.ok) {
|
||||
serverState.cloud = true
|
||||
}
|
||||
}
|
||||
reply.send(serverState)
|
||||
})
|
||||
|
||||
server.addHook('onRequest', (request, reply, done) => {
|
||||
if (request.method == 'POST') { Statistics.SystemAccess.count += 1 }
|
||||
if (request.method == 'GET') { Statistics.WebAccess.count += 1 }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue