From 8d38d7b7d44201ea95b0ed315385519361c62ce7 Mon Sep 17 00:00:00 2001 From: StarfishC Date: Thu, 12 Dec 2024 09:09:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=90=8C=E6=AD=A5singbox?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=8F=92=E4=BB=B6=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=80=89=E6=8B=A9gfs=E9=85=8D=E7=BD=AE=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...plugin-sync-singbox-configuration-gists.js | 24 +++++++++++++++---- plugins/gfs.json | 13 ++++++++-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/plugins/GFS/plugin-sync-singbox-configuration-gists.js b/plugins/GFS/plugin-sync-singbox-configuration-gists.js index f1fd1a6..5e005fb 100644 --- a/plugins/GFS/plugin-sync-singbox-configuration-gists.js +++ b/plugins/GFS/plugin-sync-singbox-configuration-gists.js @@ -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') diff --git a/plugins/gfs.json b/plugins/gfs.json index 84b6d90..932025b 100644 --- a/plugins/gfs.json +++ b/plugins/gfs.json @@ -56,8 +56,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", @@ -82,6 +82,15 @@ "component": "Input", "value": "", "options": [] + }, + { + "id": "ID_ya7dggls", + "title": "PROFILE NAME", + "description": "[选填] 配置名。填写时不弹出配置选择框,否则弹出配置选择框", + "key": "ProfileName", + "component": "Input", + "value": "", + "options": [] } ], "disabled": false,