Skip to content

Commit 8d38d7b

Browse files
committed
升级同步singbox配置插件,支持选择gfs配置进行同步
1 parent 7678ac4 commit 8d38d7b

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

plugins/GFS/plugin-sync-singbox-configuration-gists.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,27 @@ const onTask = async () => {
99

1010
const updateGist = async () => {
1111
if (!Plugin.GistId) throw '未配置GIST ID'
12-
const { id: messageId } = Plugins.message.info('正在更新 Gist...', 60 * 60 * 1000)
12+
const store = Plugins.useProfilesStore()
13+
let profile = null
14+
if (!Plugin.ProfileName) {
15+
profile = await Plugins.picker.single(
16+
'请选择要同步的配置',
17+
store.profiles.map((v) => ({
18+
label: v.name,
19+
value: v
20+
})),
21+
[]
22+
)
23+
} else {
24+
profile = store.profiles.find(item => item.name === Plugin.ProfileName)
25+
if (!profile)
26+
throw "未找到配置:" + Plugin.ProfileName
27+
}
28+
const configJsonContent = await Plugins.generateConfig(profile)
29+
const { id: messageId } = Plugins.message.info('正在更新 Gist...', 60 * 1000)
1330

1431
try {
15-
const configJsonContent = await Plugins.Readfile('data/sing-box/config.json')
16-
if (!configJsonContent) throw 'config.json 文件不存在'
17-
18-
const updatedGist = await updateGistFile(Plugin.GistId, configJsonContent)
32+
const updatedGist = await updateGistFile(Plugin.GistId, JSON.stringify(configJsonContent, null, 4))
1933
Plugins.message.update(messageId, `Gist 更新成功: ${updatedGist}`, 'success')
2034
} catch (error) {
2135
Plugins.message.update(messageId, `Gist 更新失败: ${error}`, 'error')

plugins/gfs.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
},
5757
{
5858
"id": "plugin-sync-singbox-configuration-gists",
59-
"name": "同步singbox的配置 - Gists",
60-
"description": "将sing-box的config.json同步到指定的Gist-Id下的config.json。Supported by: ccch",
59+
"name": "同步配置的singbox-config.json",
60+
"description": "将指定的配置生成config.json后同步到Gists。Supported by: StarfishC",
6161
"type": "Http",
6262
"url": "https://raw.githubusercontent.com/GUI-for-Cores/Plugin-Hub/main/plugins/GFS/plugin-sync-singbox-configuration-gists.js",
6363
"path": "data/plugins/plugin-sync-singbox-configuration-gists.js",
@@ -82,6 +82,15 @@
8282
"component": "Input",
8383
"value": "",
8484
"options": []
85+
},
86+
{
87+
"id": "ID_ya7dggls",
88+
"title": "PROFILE NAME",
89+
"description": "[选填] 配置名。填写时不弹出配置选择框,否则弹出配置选择框",
90+
"key": "ProfileName",
91+
"component": "Input",
92+
"value": "",
93+
"options": []
8594
}
8695
],
8796
"disabled": false,

0 commit comments

Comments
 (0)