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:
HalcyonAlcedo 2023-06-12 21:38:38 +08:00 committed by GitHub
parent 508beaece3
commit 317283218a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 398 additions and 141 deletions

View file

@ -77,8 +77,6 @@ const newFetch = (url, options = {}) => {
return fetch(url, mergedOptions)
}
// 后台地址
const viewHost = Config.viewHost ? `${Config.viewHost}/` : `http://127.0.0.1:${Config.serverPort || 3321}/`
export class chatgpt extends plugin {
constructor () {
let toggleMode = Config.toggleMode
@ -1393,6 +1391,7 @@ export class chatgpt extends plugin {
},
model: use,
bing: use === 'bing',
chatViewBotName: Config.chatViewBotName || '',
entry: cacheData.file,
userImg: `https://q1.qlogo.cn/g?b=qq&s=0&nk=${e.sender.user_id}`,
botImg: `https://q1.qlogo.cn/g?b=qq&s=0&nk=${Bot.uin}`,
@ -1400,7 +1399,7 @@ export class chatgpt extends plugin {
qq: e.sender.user_id
})
}
const cacheres = await fetch(viewHost + 'cache', cacheresOption)
const cacheres = await fetch(Config.viewHost ? `${Config.viewHost}/` : `http://127.0.0.1:${Config.serverPort || 3321}/` + 'cache', cacheresOption)
if (cacheres.ok) {
cacheData = Object.assign({}, cacheData, await cacheres.json())
} else {
@ -1414,7 +1413,7 @@ export class chatgpt extends plugin {
let cacheData = await this.cacheContent(e, use, content, prompt, quote, mood, suggest, imgUrls)
const template = use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index'
if (!Config.oldview) {
if (cacheData.error || cacheData.status != 200) { await this.reply(`出现错误:${cacheData.error || 'server error ' + cacheData.status}`, true) } else { await e.reply(await renderUrl(e, viewHost + `page/${cacheData.file}?qr=${Config.showQRCode ? 'true' : 'false'}`, { retType: Config.quoteReply ? 'base64' : '', Viewport: { width: Config.chatViewWidth, height: parseInt(Config.chatViewWidth * 0.56) }, func: Config.live2d ? 'window.Live2d == true' : '', dpr: Config.cloudDPR }), e.isGroup && Config.quoteReply) }
if (cacheData.error || cacheData.status != 200) { await this.reply(`出现错误:${cacheData.error || 'server error ' + cacheData.status}`, true) } else { await e.reply(await renderUrl(e, (Config.viewHost ? `${Config.viewHost}/` : `http://127.0.0.1:${Config.serverPort || 3321}/`) + `page/${cacheData.file}?qr=${Config.showQRCode ? 'true' : 'false'}`, { retType: Config.quoteReply ? 'base64' : '', Viewport: { width: Config.chatViewWidth, height: parseInt(Config.chatViewWidth * 0.56) }, func: (Config.live2d && !Config.viewHost) ? 'window.Live2d == true' : '', deviceScaleFactor: Config.cloudDPR }), e.isGroup && Config.quoteReply) }
} else {
if (Config.cacheEntry) cacheData.file = randomString()
const cacheresOption = {

View file

@ -5,12 +5,13 @@ import { generateAudio } from '../utils/tts.js'
import fs from 'fs'
import { emojiRegex, googleRequestUrl } from '../utils/emoj/index.js'
import fetch from 'node-fetch'
import { getImageOcrText, getImg, makeForwardMsg, mkdirs } from '../utils/common.js'
import { getImageOcrText, getImg, makeForwardMsg, mkdirs, renderUrl } from '../utils/common.js'
import uploadRecord from '../utils/uploadRecord.js'
import { makeWordcloud } from '../utils/wordcloud/wordcloud.js'
import { translate, translateLangSupports } from '../utils/translate.js'
import AzureTTS from '../utils/tts/microsoft-azure.js'
import VoiceVoxTTS from '../utils/tts/voicevox.js'
import { URL } from 'node:url'
let useSilk = false
try {
@ -56,6 +57,10 @@ export class Entertainment extends plugin {
{
reg: '^#ocr',
fnc: 'ocr'
},
{
reg: '^#url(|:)',
fnc: 'screenshotUrl'
}
]
})
@ -466,4 +471,31 @@ ${translateLangLabels}
await this.reply(replyMsg)
return false
}
async screenshotUrl (e) {
let url = e.msg.replace(/^#url(|:)/, '')
if (url.length === 0) { return false }
try {
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "http://" + url
}
let urlLink = new URL(url)
await e.reply(
await renderUrl(
e, urlLink.href,
{
retType: 'base64',
Viewport: {
width: Config.chatViewWidth,
height: parseInt(Config.chatViewWidth * 0.56)
},
deviceScaleFactor: Config.cloudDPR
}
),
e.isGroup && Config.quoteReply)
} catch (err) {
this.reply('无效url:' + url)
}
return true
}
}

View file

@ -254,6 +254,16 @@ export class ChatgptManagement extends plugin {
{
reg: '^#(chatgpt)?查看回复设置$',
fnc: 'viewUserSetting'
},
{
reg: '^#chatgpt导出配置',
fnc: 'exportConfig',
permission: 'master'
},
{
reg: '^#chatgpt导入配置',
fnc: 'importConfig',
permission: 'master'
}
]
})
@ -1416,4 +1426,107 @@ Poe 模式会调用 Poe 中的 Claude-instant 进行对话。需要提供 Cookie
await this.e.reply('设置成功')
this.finish('doSetOpenAIPlatformToken')
}
async exportConfig (e) {
if (e.isGroup || !e.isPrivate) {
await this.reply('请私聊发送命令', true)
return true
}
let redisConfig = {}
if (await redis.exists('CHATGPT:BING_TOKENS') != 0) {
let bingTokens = await redis.get('CHATGPT:BING_TOKENS')
if (bingTokens) { bingTokens = JSON.parse(bingTokens) } else bingTokens = []
redisConfig.bingTokens = bingTokens
} else {
redisConfig.bingTokens = []
}
if (await redis.exists('CHATGPT:CONFIRM') != 0) {
redisConfig.turnConfirm = await redis.get('CHATGPT:CONFIRM') === 'on'
}
if (await redis.exists('CHATGPT:USE') != 0) {
redisConfig.useMode = await redis.get('CHATGPT:USE')
}
const configJson = JSON.stringify({
chatConfig: Config,
redisConfig
})
console.log(configJson)
const buf = Buffer.from(configJson)
e.friend.sendFile(buf, `ChatGPT-Plugin Config ${new Date}.json`)
return true
}
async importConfig (e) {
if (e.isGroup || !e.isPrivate) {
await this.reply('请私聊发送命令', true)
return true
}
this.setContext('doImportConfig')
await e.reply('请发送配置文件')
}
async doImportConfig (e) {
const file = this.e.message.find(item => item.type === 'file')
if (file) {
const fileUrl = await this.e.friend.getFileUrl(file.fid)
if (fileUrl) {
try {
let changeConfig = []
const response = await fetch(fileUrl)
const data = await response.json()
const chatdata = data.chatConfig || {}
for (let [keyPath, value] of Object.entries(chatdata)) {
if (keyPath === 'blockWords' || keyPath === 'promptBlockWords' || keyPath === 'initiativeChatGroups') { value = value.toString().split(/[,;\|]/) }
if (Config[keyPath] != value) {
changeConfig.push({
item: keyPath,
value: typeof(value) === 'object' ? JSON.stringify(value): value,
old: typeof(Config[keyPath]) === 'object' ? JSON.stringify(Config[keyPath]): Config[keyPath],
type: 'config'
})
Config[keyPath] = value
}
}
const redisConfig = data.redisConfig || {}
if (redisConfig.bingTokens != null) {
changeConfig.push({
item: 'bingTokens',
value: JSON.stringify(redisConfig.bingTokens),
old: await redis.get('CHATGPT:BING_TOKENS'),
type: 'redis'
})
await redis.set('CHATGPT:BING_TOKENS', JSON.stringify(redisConfig.bingTokens))
}
if (redisConfig.turnConfirm != null) {
changeConfig.push({
item: 'turnConfirm',
value: redisConfig.turnConfirm ? 'on' : 'off',
old: await redis.get('CHATGPT:CONFIRM'),
type: 'redis'
})
await redis.set('CHATGPT:CONFIRM', redisConfig.turnConfirm ? 'on' : 'off')
}
if (redisConfig.useMode != null) {
changeConfig.push({
item: 'useMode',
value: redisConfig.useMode,
old: await redis.get('CHATGPT:USE'),
type: 'redis'
})
await redis.set('CHATGPT:USE', redisConfig.useMode)
}
await this.reply(await makeForwardMsg(this.e, changeConfig.map(msg => `修改项:${msg.item}\n旧数据\n\n${msg.url}\n\n新数据\n ${msg.url}`)))
} catch (error) {
console.error(error)
await e.reply('配置文件错误')
}
}
} else {
await this.reply(`未找到配置文件`, false)
return false
}
this.finish('doImportConfig')
}
}