-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.config.js
More file actions
143 lines (138 loc) · 5.32 KB
/
web.config.js
File metadata and controls
143 lines (138 loc) · 5.32 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
import { defineConfig, components } from "node-karin"
import { gameIds, getGameName } from "#GamePush.model"
import { cfg, PluginPackage } from "#GamePush.components"
export default defineConfig({
info: {
id: "karin-plugin-gamepush",
name: "游戏更新推送插件",
author: {
name: "RainBow",
home: "https://github.com/rainbowwarmth/",
avatar: "https://github.com/rainbowwarmth.png"
},
icon: {
name: "game",
size: 24,
color: "#B2A8D3"
},
version: PluginPackage.version,
description: PluginPackage.description
},
components: async () => {
const currentConfig = cfg.getFrontendConfig() || {}
return gameIds.map((gameId) => {
const gameConfigArray = currentConfig[gameId] || []
const gameConfig = gameConfigArray.length > 0 ? gameConfigArray[0] : {}
const gameName = getGameName(gameId)
const pushGroupsAsString = (gameConfig.pushGroups || []).map((item) => {
return typeof item === "string" ? item : `${item.botId}:${item.groupId}`
})
return components.accordion.create(`${gameId}`, {
label: `${gameName}推送设置`,
title: `${gameName}推送设置`,
children: [
components.accordion.createItem(`${gameId}`, {
title: `${gameName}推送相关`,
className: "ml-4 mr-4",
subtitle: `此处用于管理${gameName}的推送设置`,
children: [
components.switch.create(`enable`, {
label: "启用推送",
defaultSelected: gameConfig.enable !== undefined ? gameConfig.enable : true,
description: `是否启用${gameName}的游戏更新推送`
}),
components.switch.create(`log`, {
label: "启用日志",
defaultSelected: gameConfig.log !== undefined ? gameConfig.log : true,
description: `是否启用${gameName}的游戏日志显示`
}),
components.input.string(`cron`, {
label: "定时推送表达式",
placeholder: "例如: 0 0/5 * * * * (每5分钟)",
defaultValue: gameConfig.cron || "0 0/5 * * * *",
description: "使用Cron表达式设置推送时间间隔"
}),
components.input.group(`pushGroups`, {
label: "推送群组",
maxRows: 10,
data: pushGroupsAsString || [],
template: components.input.string("group-item", {
placeholder: "格式: 机器人账号:群号",
label: "群组设置"
}),
description: "每个群组格式为: '机器人账号:群号'"
}),
components.radio.group(`pushChangeType`, {
label: "推送变更类型",
orientation: "horizontal",
defaultValue: gameConfig.pushChangeType || "1",
radio: [
components.radio.create("type-1", {
label: "图片消息",
description: "以图片的格式推送更新通知",
value: "1"
}),
components.radio.create("type-2", {
label: "文字消息",
description: "以文字的格式推送更新通知",
value: "2"
})
],
description: "选择推送的变更类型"
}),
components.radio.group(`html`, {
label: "html模板",
orientation: "horizontal",
defaultValue: gameConfig.html || "Simple",
radio: [
components.radio.create("type-1", {
label: "默认模板",
description: "以默认的html模板渲染推送内容",
value: "default"
}),
components.radio.create("type-2", {
label: "简约模板",
description: "以简约的html模板渲染推送内容",
value: "Simple"
})
],
description: "请选择渲染的html模板"
})
]
})
]
})
})
},
save: async (config) => {
console.log("收到配置保存请求:", config)
const saveData = {}
gameIds.forEach((gameId) => {
const gameSettings = config[gameId] || []
const gameConfig = gameSettings.length > 0 ? gameSettings[0] : {}
const enable = gameConfig.enable !== undefined ? gameConfig.enable : true
const log = gameConfig.log !== undefined ? gameConfig.log : true
const cron = gameConfig.cron || "0 0/5 * * * *"
const pushChangeType = gameConfig.pushChangeType || "1"
const pushGroups = gameConfig.pushGroups || []
const html = gameConfig.html || "default"
saveData[gameId] = [
{
enable,
cron,
log,
pushGroups,
pushChangeType,
html
}
]
})
console.log("整理后的保存数据:", saveData)
const result = await cfg.saveFromFrontend(saveData)
console.log("配置保存结果:", result)
return {
success: result.success,
message: result.message || "配置保存成功"
}
}
})