Skip to content

Commit

Permalink
feat: ProxyUtils 中增加 Gist 类; 补充 demo.js 中的示例
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed May 4, 2024
1 parent 3b85d31 commit 92e1e4a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.304",
"version": "2.14.305",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions backend/src/core/proxy-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { FILES_KEY, MODULES_KEY } from '@/constants';
import { findByName } from '@/utils/database';
import { produceArtifact } from '@/restful/sync';
import { getFlag, getISO } from '@/utils/geo';
import Gist from '@/utils/gist';

function preprocess(raw) {
for (const processor of PROXY_PREPROCESSORS) {
Expand Down Expand Up @@ -272,6 +273,7 @@ export const ProxyUtils = {
yaml: YAML,
getFlag,
getISO,
Gist,
};

function tryParse(parser, line) {
Expand Down
37 changes: 37 additions & 0 deletions scripts/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function operator(proxies = [], targetPlatform, context) {
// yaml, // yaml 解析和生成
// getFlag, // 获取 emoji 旗帜
// getISO, // 获取 ISO 3166-1 alpha-2 代码
// Gist, // Gist 类
// }

// 示例: 给节点名添加前缀
Expand Down Expand Up @@ -94,6 +95,42 @@ function operator(proxies = [], targetPlatform, context) {
// produceType: 'internal' // 'internal' produces an Array, otherwise produces a String( ProxyUtils.yaml.safeLoad('YAML String').proxies )
// })

// 4. 一个比较折腾的方案: 在脚本操作中, 把内容同步到另一个 gist

// async function operator(proxies = []) {
// const $ = $substore
// const GITHUB_TOKEN = 'ghp_xxxxxxxxxxxxxxxxxxxxx'
// const GIST_NAME = 'share'
// const FILENAME = 'mihomo.yaml'
// let files = {}
// let content = await produceArtifact({
// type: 'subscription',
// subscription: {},
// content: 'proxies:\n' + proxies.map((proxy) => ' - ' + JSON.stringify(proxy) + '\n').join(''),
// platform: 'ClashMeta',
// })
// const manager = new ProxyUtils.Gist({
// token: GITHUB_TOKEN,
// key: GIST_NAME,
// });
// files[encodeURIComponent(FILENAME)] = {
// content,
// };
// const res = await manager.upload(files);
// let body = {};
// try {
// body = JSON.parse(res.body);
// // eslint-disable-next-line no-empty
// } catch (e) {}
// const raw_url =
// body.files[encodeURIComponent(FILENAME)]?.raw_url;
// console.log(raw_url)
// const new_url = raw_url?.replace(/\/raw\/[^/]*\/(.*)/, '/raw/$1');
// console.log(new_url)
// $.notify('🌍 Sub-Store', `更新到 Gist: ${new_url}`);
// return proxies
// }

// // YAML
// ProxyUtils.yaml.load('YAML String')
// ProxyUtils.yaml.safeLoad('YAML String')
Expand Down

0 comments on commit 92e1e4a

Please sign in to comment.