From 92e1e4a0fbd43910e8b4a3006e196082ce2ec5fd Mon Sep 17 00:00:00 2001 From: xream Date: Sat, 4 May 2024 19:25:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20ProxyUtils=20=E4=B8=AD=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20Gist=20=E7=B1=BB;=20=E8=A1=A5=E5=85=85=20demo.js=20?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/core/proxy-utils/index.js | 2 ++ scripts/demo.js | 37 +++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/backend/package.json b/backend/package.json index be0c5b0..db767d2 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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": { diff --git a/backend/src/core/proxy-utils/index.js b/backend/src/core/proxy-utils/index.js index 7d8699f..6a0aca5 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -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) { @@ -272,6 +273,7 @@ export const ProxyUtils = { yaml: YAML, getFlag, getISO, + Gist, }; function tryParse(parser, line) { diff --git a/scripts/demo.js b/scripts/demo.js index e1e6133..018ef47 100644 --- a/scripts/demo.js +++ b/scripts/demo.js @@ -39,6 +39,7 @@ function operator(proxies = [], targetPlatform, context) { // yaml, // yaml 解析和生成 // getFlag, // 获取 emoji 旗帜 // getISO, // 获取 ISO 3166-1 alpha-2 代码 + // Gist, // Gist 类 // } // 示例: 给节点名添加前缀 @@ -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')