chatgpt-plugin/utils/config.js
2023-03-02 18:02:55 +08:00

65 lines
2.1 KiB
JavaScript

import fs from 'fs'
import lodash from 'lodash'
const defaultConfig = {
blockWords: ['屏蔽词1', '屏蔽词b'],
promptBlockWords: ['屏蔽词1', '屏蔽词b'],
imgOcr: true,
defaultUsePicture: false,
autoUsePicture: true,
autoUsePictureThreshold: 1200,
conversationPreserveTime: 0,
toggleMode: 'at',
quoteReply: true,
showQRCode: true,
cacheUrl: 'https://content.alcedogroup.com',
cacheEntry: false,
apiKey: '',
drawCD: 30,
model: '',
temperature: 0.8,
api: 'https://chatgpt.duti.tech/api/conversation',
apiBaseUrl: 'https://chatgpt.duti.tech/api',
plus: false,
promptPrefixOverride: 'Your answer shouldn\'t be too verbose. Prefer to answer in Chinese.',
assistantLabel: 'ChatGPT',
thinkingTips: true,
username: '',
password: '',
UA: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
headless: false,
chromePath: '',
'2captchaToken': '',
proxy: '',
debug: true,
defaultTimeoutMs: 120000,
chromeTimeoutMS: 120000,
version: '2.0.6'
}
const _path = process.cwd()
let config = {}
if (fs.existsSync(`${_path}/plugins/chatgpt-plugin/config/config.js`)) {
const fullPath = fs.realpathSync(`${_path}/plugins/chatgpt-plugin/config/config.js`)
config = (await import(`file://${fullPath}`)).default
} else if (fs.existsSync(`${_path}/plugins/chatgpt-plugin/config/index.js`)) {
// 兼容旧版本
const fullPath = fs.realpathSync(`${_path}/plugins/chatgpt-plugin/config/index.js`)
config = (await import(`file://${fullPath}`)).Config
}
config = Object.assign({}, defaultConfig, config)
export const Config = new Proxy(config, {
set (target, property, value) {
target[property] = value
const change = lodash.transform(target, function (result, value, key) {
if (!lodash.isEqual(value, defaultConfig[key])) {
result[key] = value
}
})
try {
fs.writeFileSync(`${_path}/plugins/chatgpt-plugin/config/config.js`, `export default ${JSON.stringify(change, '', '\t')}`, { flag: 'w' })
} catch (err) {
console.error(err)
return false
}
return true
}
})