Skip to content

Commit

Permalink
Merge pull request #13 from StarfishC/main
Browse files Browse the repository at this point in the history
新增插件-同步singbox配置到指定的gistid
  • Loading branch information
Ayideyia authored Oct 12, 2024
2 parents 0868f84 + 9b6db00 commit 31704dc
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
44 changes: 44 additions & 0 deletions plugins/GFS/plugin-sync-singbox-configuration-gists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const onRun = async () => {
await updateGist();
};

const updateGist = async () => {
if (!Plugin.GistId) throw '未配置GIST ID';
const { id: messageId } = Plugins.message.info('正在更新 Gist...', 60 * 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);
Plugins.message.update(messageId, `Gist 更新成功: ${updatedGist}`, 'success');
} catch (error) {
Plugins.message.update(messageId, `Gist 更新失败: ${error}`, 'error');
} finally {
await Plugins.sleep(1500).then(() => Plugins.message.destroy(messageId));
}
};


async function updateGistFile(gistId, configJsonContent) {
if (!Plugin.Authorization) throw '未配置TOKEN';

const { body } = await Plugins.HttpPatch(`https://api.github.com/gists/${gistId}`, {
'User-Agent': 'GUI.for.Cores',
'Content-Type': 'application/json',
'X-GitHub-Api-Version': '2022-11-28',
Accept: 'application/vnd.github+json',
Connection: 'close',
Authorization: 'Bearer ' + Plugin.Authorization
}, {
files: {
'config.json': {
content: configJsonContent
}
}
});
if (body.message) {
throw body.message
}
return 'ok'
}
34 changes: 34 additions & 0 deletions plugins/gfs.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,39 @@
"disabled": false,
"install": true,
"installed": false
},
{
"id": "plugin-sync-singbox-configuration-gists",
"name": "同步singbox的配置 - Gists",
"description": "将sing-box的config.json同步到指定的Gist-Id下的config.json。Supported by: ccch",
"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",
"triggers": ["on::manual"],
"menus": {},
"status": 0,
"configuration": [
{
"id": "ID_z8ofmiru",
"title": "TOKEN",
"description": "拥有Gists访问权限的 token",
"key": "Authorization",
"component": "Input",
"value": "",
"options": []
},
{
"id": "ID_b22adg38",
"title": "GIST ID",
"description": "已创建好的GistId",
"key": "Secret",
"component": "Input",
"value": "",
"options": []
}
],
"disabled": false,
"install": false,
"installed": false
}
]

0 comments on commit 31704dc

Please sign in to comment.