-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguoba.support.js
More file actions
160 lines (151 loc) · 5.44 KB
/
Copy pathguoba.support.js
File metadata and controls
160 lines (151 loc) · 5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* 锅巴(Guoba-Plugin)WebUI 配置支持
* 参照 Guoba-Template-Plugin 实现:命名导出 supportGuoba() 自动接入,
* getConfigData / setConfigData 读写 config.json(见 components/config.js)。
* 前提:已安装 Guoba-Plugin,Web 端「插件配置」→ JM 插件。
*/
import { readConfig, writeConfig } from './components/config.js'
import path from 'path'
const _path = path.join(process.cwd().replace(/\\/g, '/'), '/plugins/jm-plugin')
/** 将 JSON 数组字符串解析为数组,失败返回 [] */
function parseJsonArray (str) {
if (!str) return []
try {
const arr = JSON.parse(str)
return Array.isArray(arr) ? arr : []
} catch (e) {
return []
}
}
/** 解析 python 候选:兼容数组 / 逗号(,、;空格) 分隔字符串 */
function parsePython (val) {
if (Array.isArray(val)) return val.map(s => String(s).trim()).filter(Boolean)
return String(val || '').split(/[,,、\s]+/).filter(Boolean)
}
export function supportGuoba () {
return {
// 插件信息(显示在锅巴 Web 端菜单)
pluginInfo: {
name: 'jm-plugin',
title: 'JM 插件',
description: 'JM 漫画插件:登录 / 收藏 / 搜索 / 详情 / 排行 / 下载(基于 jmcomic 库)',
author: '@githubmof',
authorLink: 'https://github.com/githubmof',
link: 'https://github.com/githubmof/jm-plugin',
isV3: true,
isV2: false,
// 配置项 >= 3 个时自动显示在左侧菜单
showInMenu: 'auto',
icon: 'mdi:book-open-page-variant',
iconColor: '#ff6b81',
iconPath: path.join(_path, '/resources/icon.png'),
},
// 配置项信息(WebUI 表单)
configInfo: {
schemas: [
{ label: '基础配置', component: 'SOFT_GROUP_BEGIN' },
{
field: 'python',
label: 'Python 命令',
bottomHelpMessage: 'Python 解释器,多个候选用逗号分隔(默认 python3, python)',
component: 'Input',
componentProps: {
placeholder: 'python3, python',
trimValue: true
}
},
{
field: 'proxy',
label: 'HTTP 代理',
bottomHelpMessage: '访问 JM 失败时配置,如 http://127.0.0.1:7890',
component: 'Input',
componentProps: {
placeholder: 'http://127.0.0.1:7890',
trimValue: true
}
},
{
field: 'baseUrl',
label: '自定义 API 域名',
bottomHelpMessage: '每行一个域名,覆盖默认移动端 API 域名列表(留空使用内置)',
component: 'InputTextArea',
componentProps: {
placeholder: 'www.cdnhjk.net',
rows: 3
}
},
{ label: '权限与通知', component: 'SOFT_GROUP_BEGIN' },
{
field: 'masterOnly',
label: '仅限主人',
bottomHelpMessage: '开启后除帮助外所有命令仅主人可用',
component: 'Switch'
},
{
field: 'notify',
label: '下载完成通知',
bottomHelpMessage: 'auto:群内 / 私聊通知;text:仅写入日志',
component: 'Select',
componentProps: {
options: [
{ label: '自动通知(推荐)', value: 'auto' },
{ label: '仅写入日志', value: 'text' }
]
}
},
{
field: 'pdfCacheMax',
label: 'PDF 缓存上限',
bottomHelpMessage: '服务器保留最近 N 个 PDF (0 = 不限制),超出删除最早的',
component: 'InputNumber',
componentProps: { min: 0, max: 500, placeholder: '20' }
},
{ label: '帮助文档', component: 'SOFT_GROUP_BEGIN' },
{
field: 'help',
label: '自定义帮助文档',
helpMessage: '留空则使用内置默认帮助',
bottomHelpMessage: '发送 #jm帮助 时展示的内容,支持换行与 emoji,适合手机查看',
component: 'InputTextArea',
componentProps: {
placeholder: '📖 JM 插件帮助\n━━━━━━━━━━━━\n发送 #jm帮助 查看',
rows: 10
}
}
],
// 读取配置(回填表单)
getConfigData () {
const cfg = readConfig()
return {
python: (cfg.python || []).join(', '),
proxy: cfg.proxy || '',
baseUrl: parseJsonArray(cfg.baseUrl).join('\n'),
masterOnly: !!cfg.masterOnly,
notify: cfg.notify === 'text' ? 'text' : 'auto',
help: cfg.help || '',
pdfCacheMax: Number(cfg.pdfCacheMax) || 20
}
},
// 保存配置(写回 config.json)
setConfigData (data, { Result }) {
const ret = writeConfig({
python: parsePython(data.python),
proxy: String(data.proxy || '').trim(),
baseUrl: JSON.stringify(
String(data.baseUrl || '')
.split('\n').map(s => s.trim()).filter(Boolean)
),
masterOnly: !!data.masterOnly,
notify: data.notify === 'text' ? 'text' : 'auto',
help: String(data.help || '').trim(),
pdfCacheMax: Number(data.pdfCacheMax) || 20
})
if (!ret.ok) {
logger?.error?.('[jm-plugin] 锅巴保存配置失败:', ret.error)
return Result.error(`保存失败:${ret.error}`)
}
return Result.ok({}, '保存成功~')
}
}
}
}