Skip to content

Commit

Permalink
Merge pull request #22 from StarfishC/main
Browse files Browse the repository at this point in the history
升级同步singbox配置插件,支持选择gfs配置进行同步
  • Loading branch information
Ayideyia authored Dec 12, 2024
2 parents 8b3e800 + 8d38d7b commit 59a9197
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
24 changes: 19 additions & 5 deletions plugins/GFS/plugin-sync-singbox-configuration-gists.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,27 @@ const onTask = async () => {

const updateGist = async () => {
if (!Plugin.GistId) throw '未配置GIST ID'
const { id: messageId } = Plugins.message.info('正在更新 Gist...', 60 * 60 * 1000)
const store = Plugins.useProfilesStore()
let profile = null
if (!Plugin.ProfileName) {
profile = await Plugins.picker.single(
'请选择要同步的配置',
store.profiles.map((v) => ({
label: v.name,
value: v
})),
[]
)
} else {
profile = store.profiles.find(item => item.name === Plugin.ProfileName)
if (!profile)
throw "未找到配置:" + Plugin.ProfileName
}
const configJsonContent = await Plugins.generateConfig(profile)
const { id: messageId } = Plugins.message.info('正在更新 Gist...', 60 * 1000)

try {
const configJsonContent = await Plugins.Readfile('data/sing-box/config.json')
if (!configJsonContent) throw 'config.json 文件不存在'

const updatedGist = await updateGistFile(Plugin.GistId, configJsonContent)
const updatedGist = await updateGistFile(Plugin.GistId, JSON.stringify(configJsonContent, null, 4))
Plugins.message.update(messageId, `Gist 更新成功: ${updatedGist}`, 'success')
} catch (error) {
Plugins.message.update(messageId, `Gist 更新失败: ${error}`, 'error')
Expand Down
13 changes: 11 additions & 2 deletions plugins/gfs.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
},
{
"id": "plugin-sync-singbox-configuration-gists",
"name": "同步singbox的配置 - Gists",
"description": "将sing-box的config.json同步到指定的Gist-Id下的config.json。Supported by: ccch",
"name": "同步配置的singbox-config.json",
"description": "将指定的配置生成config.json后同步到Gists。Supported by: StarfishC",
"type": "Http",
"url": "https://raw.githubusercontent.com/GUI-for-Cores/Plugin-Hub/main/plugins/GFS/plugin-sync-singbox-configuration-gists.js",
"path": "data/plugins/plugin-sync-singbox-configuration-gists.js",
Expand All @@ -120,6 +120,15 @@
"component": "Input",
"value": "",
"options": []
},
{
"id": "ID_ya7dggls",
"title": "PROFILE NAME",
"description": "[选填] 配置名。填写时不弹出配置选择框,否则弹出配置选择框",
"key": "ProfileName",
"component": "Input",
"value": "",
"options": []
}
],
"disabled": false,
Expand Down

0 comments on commit 59a9197

Please sign in to comment.