1 Star 0 Fork 2

会飞的锤子/MEMZ-Plugin

forked from MEMZ/MEMZ-Plugin 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
guoba.support.js 2.80 KB
一键复制 编辑 原始数据 按行查看 历史
叶殇 提交于 2024-04-20 18:46 . 额啊
import path from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import getconfig from './model/configget.js';
import fs from 'fs';
import yaml from 'yaml';
import lodash from 'lodash'
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
export function supportGuoba() {
return {
pluginInfo: {
name: `MEMZ-Plugin`,
title: 'MEMZ插件(MEMZ-Plugin)',
author: '@MEMZ',
authorLink: 'https://gitee.com/memzjs',
link: 'https://gitee.com/memzjs/memz-plugin',
isV3: true,
isV2: false,
description: `组织内部使用插件,基于**ChatGPT** && **Ctrl C+V**`,
// 显示图标,此为个性化配置
// 图标可在 https://icon-sets.iconify.design 这里进行搜索
icon: 'mdi:stove',
// 图标颜色,例:#FF0000 或 rgb(255, 0, 0)
iconColor: '#d19f56',
// 如果想要显示成图片,也可以填写图标路径(绝对路径)
},
configInfo: {
// 配置项 schemas
schemas: [
{
field: 'SMTPUser',
label: 'SMTPUser',
bottomHelpMessage: 'SMTP用户名',
component: 'Input'
},
{
field: 'SMTPPass',
label: 'SMTPPass',
bottomHelpMessage: 'SMTP密码',
component: 'Input'
},
{
field: 'SMTPPort',
label: 'SMTPPort',
bottomHelpMessage: 'SMTP端口号',
component: 'Input'
},
{
field: 'SMTPURL',
label: 'SMTPURL',
bottomHelpMessage: 'SMTP服务器地址 ',
component: 'Input'
},
{
field: 'SMTPAll',
label: 'SMTPAll key',
bottomHelpMessage: 'SMTP是否全部人可用',
component: 'Switch'
},
],
async getConfigData() {
let { config } = getconfig(`config`, `all.config`)
return config;
},
async setConfigData(data, { Result }) {
// 1.读取现有配置文件
const configFilePath = path.join(__dirname,'config','all.config.yaml');
let config = {};
if (fs.existsSync(configFilePath)) {
const configContent = fs.readFileSync(configFilePath, 'utf8');
config = yaml.parse(configContent) || {};
}
// 2. 更新配置对象
for (const [keyPath, value] of Object.entries(data)) {
lodash.set(config, keyPath, value);
}
// 3. 将更新后的配置对象写回文件
const updatedConfigYAML = yaml.stringify(config);
fs.writeFileSync(configFilePath, updatedConfigYAML, 'utf8');
logger.mark(`[MEMZ:配置文件]配置文件更新`)
return Result.ok({}, '保存成功~');
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/zzwh12/memz-plugin.git
git@gitee.com:zzwh12/memz-plugin.git
zzwh12
memz-plugin
MEMZ-Plugin
master

搜索帮助